iOS中的UIView的基本属性

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];;
    //320*568   5s
    //创建一个宽高为200的视图,添加到屏幕的中间
    //视图的位置是相对于父视图左边原点的位置
    //UIView 重要属性
    //1.frame包含orgin(左上角坐标),seze(矩形的大小)
    //2.center 视图相对对父视图坐标系的中心点
    //3.bounds 发生变化,影响的是自身坐标系的坐标原点,进而影响子视图的位置变化

//    UIView *centerView = [[UIView alloc] initWithFrame:CGRectMake(60,184, 200, 200)];
//    [self.window addSubview:centerView];
//    centerView.backgroundColor = [UIColor redColor];
//
//    [centerView release];
//
//
//    //更改centerview相对自身坐标系的位置
//    //centerView自己位置没有遍,bounds改变的是centeView自己的坐标原点
//    //造成centerView字视图的位置改变
//    centerView.bounds = CGRectMake(50, 50, 200, 200);
//
//
//    //创建一个宽高为100的视图,添加到屏幕的中间
//    UIView *centerView1 = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
//    [centerView addSubview:centerView1];
//    centerView1.backgroundColor = [UIColor greenColor];
//
//    [centerView1 release];
//    

    UIView *centerView1 = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
    [self.window addSubview:centerView1];
    centerView1.backgroundColor = [UIColor redColor];

    [centerView1 release];

    UIView *centerView2 = [[UIView alloc] initWithFrame:CGRectMake(50+80, 50+80, 100, 100)];
    [self.window addSubview:centerView2];
    centerView2.backgroundColor = [UIColor greenColor];

    [centerView2 release];

    UIView *centerView3 = [[UIView alloc] initWithFrame:CGRectMake(50+80+80, 50+80+80, 100, 100)];
    [self.window addSubview:centerView3];
    centerView3.backgroundColor = [UIColor yellowColor];

    [centerView3 release];

    UIView *centerView4 = [[UIView alloc] initWithFrame:CGRectMake(50+80, 50+80+80+80, 100, 100)];
    [self.window addSubview:centerView4];
    centerView4.backgroundColor = [UIColor grayColor];

    [centerView4 release];

    UIView *centerView5 = [[UIView alloc] initWithFrame:CGRectMake(50, 50+80+80+80+80, 100, 100)];
    [self.window addSubview:centerView5];
    centerView5.backgroundColor = [UIColor orangeColor];

    [centerView5 release];

    //打印brownView的父视图
    NSLog(@"%@",centerView1.superview);

    //打印window的子视图
    NSLog(@"%@",self.window.subviews);

    //创建一个灰色视图
    UIView *blackView = [[UIView alloc] initWithFrame:CGRectMake(50, 100, 200, 200)];
    blackView.backgroundColor = [UIColor blackColor];
    [self.window addSubview:blackView];
    //将视图插入指定位置
    //[self.window insertSubview:blackView atIndex:0];
    //在指定视图的下面
    //[self.window insertSubview:blackView belowSubview:centerView1];
    //在指定视图的上面
    //[self.window insertSubview:blackView aboveSubview:centerView1];
    [blackView release];
    //交换两个视图
    //[self.window exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
    //将视图移到最前面
    //[self.window sendSubviewToBack:centerView1];
    //将视图移到最后面
    //[self.window bringSubviewToFront:centerView2];

    //删除指定视图
    //[centerView2 removeFromSuperview];
    //视图间的层级关系
    //1.子视图肯定会在父视图的前面
    //2.后添加的视图如果和之前的视图有重叠的部分,会覆盖掉之前的视图
    //3.如果要插入或者改变视图的层级关系,都需要父视图来管理
    //4.父视图通过数组来管理子视图的层级关系
    //5.如果想从父视图上移除,自己移除即可 例如[centerView2 removeFromSuperview];

    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}
时间: 2024-08-07 04:22:34

iOS中的UIView的基本属性的相关文章

iOS中的UIView的基本属性1

@interface AppDelegate () @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //UIweindow 应用程序的窗口,用于将内容展示给用户 self.window = [[[UIWindow alloc] initWithFrame:[[

在iOS中获取UIView的所有层级结构 相关

在iOS中获取UIView的所有层级结构 应用场景 在实际 iOS 开发中,很多时候都需要知道某个 UI 控件中包含哪些子控件,并且分清楚它们的层级结构和自个的 frame 以及 bounds ,以便我们完成复杂的 UI 布局,下面的代码就能很方便的获取某个 UI 控件的所有的层级结构,我们可以用它计算,然后把结果写入到本地磁盘,导出成XML文件,这样我们就可以很直观的看出它内部的细节. /** * 返回传入veiw的所有层级结构 * * @param view 需要获取层级结构的view *

iOS中自定义UIView(用接口获取Lable和TextFile中的值)

NSArray *arrayText = @[@"用户名",@"密码",@"确认密码",@"手机号",@"邮箱"]; NSArray *placeholders = @[@"请输入用户名",@"请输入密码",@"请确认密码",@"请输入手机号",@"请输入邮箱"]; NSInteger y = 30; for

iOS中UIView之间布局及跳转的几种方式

UIView是iOS开发中所有视图的基类, 表示屏幕上的一块矩形区域, 同时可以处理该区域的绘制和触摸事件. UIViewController是视图控制器的基类, 用来处理屏幕之间的切换等操作, 提供视图管理模型. 一个UIViewController管理一个层级的UIView. 而RootViewController就是iOS应用启动时被载入的第一个视图控制器(可在main.storyboard中指定), 展示APP启动成功后的第一个界面. 因此, iOS中在各个UIViewControlle

iOS中中UIView头文件详细解析

@interface UIView : UIResponder<NSCoding, UIAppearance, UIAppearanceContainer, UIDynamicItem> /** *  通过一个frame来初始化一个UI控件 */ - (id)initWithFrame:(CGRect)frame; // YES:能够跟用户进行交互 @property(nonatomic,getter=isUserInteractionEnabled) BOOL userInteraction

ios中layer动画和UIView动画代码总结

kCATransitionFade淡出 kCATransitionMoveIn覆盖原图 kCATransitionPush推出 kCATransitionReveal底部显出来 pageCurl   向上翻一页 pageUnCurl 向下翻一页 rippleEffect 滴水效果 suckEffect 收缩效果,如一块布被抽走 cube 立方体效果 oglFlip 上下翻转效果 #pragma mark UIView 动画 - (IBAction)pressClick1:(id)sender {

IOS中复制一份UIView

IOS中复制一份UIView by 伍雪颖 - (UIView*)duplicate:(UIView*)view { NSData * tempArchive = [NSKeyedArchiver archivedDataWithRootObject:view]; return [NSKeyedUnarchiver unarchiveObjectWithData:tempArchive]; }

iOS 中 UIView 和 CALayer 的关系

UIView 有一个名叫 layer ,类型为 CALayer 的对象属性,它们的行为很相似,主要区别在于:CALayer 继承自 NSObject ,不能够响应事件. 这是因为 UIView 除了负责响应事件 ( 继承自 UIReponder ) 外,它还是一个对 CALayer 的底层封装.可以说,它们的相似行为都依赖于 CALayer 的实现,UIView 只不过是封装了它的高级接口而已. 那 CALayer 是什么呢? CALayer(图层) 文档对它定义是:管理基于图像内容的对象,允许

ios中的事件处理、响应者链条以及第一响应者

在ios中,事件UIEvent类来表示,当一个事件发生时,系统会搜集的相关事件信息,创建一个UIEvent对象,最后将该事件转发给应用程序对象(UIApplication).日常生活中,主要有三种类型的事件:触摸事件,加速计事件以及远程遥控事件.下面是官方的一张图片: 当用户通过以上方式触发一个事件时,会将相应的事件对象添加到UIApplication的事件队列中.UIApplication会循环的从队列中拿出第一个事件来处理.首先将该事件分发给UIApplication 的主窗口对象(KeyW