码迷,mamicode.com
首页 > 其他好文 > 详细

UI部分(代码启动界面,frame,bounds,UIView)

时间:2015-12-18 16:44:56      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:

1.在网上看到,团队合作项目时,会比较多时候用代码和xib联合起来设计ui。

  如何在不用storyboard的情况下启动一个页面呢?

  首先要在你的项目页面将启动页面的main interface设置为空!

 

 

 

  技术分享

接着在你的项目delegate文件里面设置代码,就是那个管理app生命周期的文件!(注意不是view生命周期的文件!)

storyboard是自带有实例化了的windows 。

而用代码启动时,必须要知道我们需要自己实例化一个窗口(window)来容纳我们需要展示的各种内容还要设置在这个文件中设置rootViewController!!

各种内容以view的形式形成一定的层次结构(譬如这个view是在另外一个view的显示中,或者并列显示即不存在包含关系,需要自己设计)展示在一个窗口中,在iOS中一般情况下只需要一个主窗口就行了,但是mac里面的就不一定。rootViewController就是至少设置一个view在window上面,因为一般iOS APP中window是不用来显示任何其他东西,他是作为一个容器,里面存放的是各种View。button,label其实也是属于view的一种,因为他在官方文档中说了继承view这个类。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];//初始化并设置尺度,不设置或设置为nil则app无法运行
   [self.window setBackgroundColor:[UIColor whiteColor]];//设置window背景的颜色,

   self.window.rootViewController
= [[ViewController alloc]init];   //这个view一般在ViewController中初始化,不设置或设置为nil则app无法运行

[self.window makeKeyAndVisible];
//这行代码会让包含了视图控制器视图的Window窗口显示在屏幕上。若不设置则一片漆黑
   return YES; }

上面所示的内容是在Appdelegate.m文件中的,在他的头文件中,系统自动为我们生成了window这个变量。所以在这个函数是在app启动完后(after application launch)我们要做什么,当然我们直接为他实例化一个window并在初始化的时候设置了他的尺寸,下面则是官方api关于获取当前窗口的尺寸,是物理尺寸即不同的iphone他会获取不同的尺寸,同样的水平和垂直放置的尺寸也是不同的,这个bounds属于是只读的属性,不能设置。技术分享



 

 

关于UIView的属性以及frame,bounds等区别(参考博文:http://blog.csdn.net/mad1989/article/details/8711697

里面讲的十分清楚,在官方api中解释到

The frame defines the origin and dimensions of the view in the coordinate system of its superview and is commonly used during layout to adjust the size or position of the view。

The bounds defines the internal dimensions of the view as it sees them and is used almost exclusively in custom drawing code. The size portion of the frame and bounds rectangles are coupled together so that changing the size of either rectangle updates the size of both.

frame定义了这个view 的起点,以及他的尺寸大小(高度和宽度),可以用来调整这个view的位置。前两个参数是在super view的坐标下这个view的位置。

对于bounds,他定义了自己的这个view的坐标系起点,和这个view的大小。默认情况下自己的坐标系起点也为(0,0),更改bounds的起点位置,则对这个view中的subview位置造成了影响,因为对于自己这个view中的subview,他的起点就不是(0,0),而是更改bounds后中的起点位置。

技术分享

图来自上面的链接,其中有例子帮助理解。

UI部分(代码启动界面,frame,bounds,UIView)

标签:

原文地址:http://www.cnblogs.com/hams/p/5054125.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!