您的位置:首页 > 产品设计 > UI/UE

UI_视图界面

2016-01-15 21:52 471 查看
#import "AppDelegate.h"

//宏定义
#define RGBA(r,g,b,a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)]

#define STRINGSUB(s,i) [(s) substringToIndex:(i)];

@interface AppDelegate ()

@end

@implementation AppDelegate

//苹果6的屏幕大小为:宽(Width)375  高(Height)667

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    

//设置整个页面大小为屏幕大小
    self.window = [[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]];

//*新建视图,大小
    UIView *myView = [[UIViewalloc]initWithFrame:CGRectMake(100,100, 100, 100)];
    //*设置视图颜色
    [myView setBackgroundColor:[UIColorredColor]];
    //视图的透明度(范围0~1)
    myView.alpha = 0.5;
    //将当前视图隐藏是一个Bool值,  YES
& NO 默认值为NO
    myView.hidden = NO;

    //*将试图显示在页面上
    [self.windowaddSubview:myView];

    

    
    //得到myView的frame,并将它转换为字符串类型
    NSString *frame = NSStringFromCGRect(myView.frame);

    
    //得到myView的bounds,并将它转换为字符串类型
    NSString *bounds =NSStringFromCGRect(myView.bounds);

    
    NSLog(@"frame = %@",frame);
    NSLog(@"bounds = %@",bounds);

    

    

    //改变一下bounds的值.frame参照的是父视图的坐标系,意思是说,frame是myView在父视图的位置的体现。bounds参照的是本身,当bounds改变之后,就会影响在myView上面子视图的位置。
    myView.bounds = CGRectMake(20, 20, 100, 100);

    

    //视图的中心点  参照的坐标系为父视图。
    //    myView.center
    NSLog(@"center = %@",NSStringFromCGPoint(myView.center));

    

    //将视图放到屏幕的最中间
    myView.center = self.window.center;

    
    NSLog(@"center = %@",NSStringFromCGPoint(myView.center));

    

    

    //center是OC语言下,调用属性方法的点语法;

    //point, X是结构体的点语法,也就是C语言中的点语法,诸位点的意义不同,所以不能共同使用。
    //    CGPoint point = myView.center;
    //    point.x  = 100;

    
    //父视图的bounds改变子视图一定改变

    

    

    

//练习重叠视图,在同一个中心点上

    //练习重叠视图,在同一个中心点上

    
    for (int i =0; i<5; i++) {
        UIView *myView1 = [[UIViewalloc]initWithFrame:CGRectMake(0,0, 100-i*10,100-i*10)];

        

        //每一个视图都可以加标记,让我们通过标记找到该视图。如果不设置该标记,系统会默认给一个标记值。所以我们人为赋值,不能和系统给的标记值冲突。所以一般标记值从1000起步。(其实就是标记值)
        myView1.tag = 1000+i;

        
        myView1.center = myView.center;

    
        //颜色给定
        //[myView1 setBackgroundColor:RGBA(i*10+100, i*10+100, i*10+100, 1)];
        //颜色改为随机色
        [myView1 setBackgroundColor:RGBA(arc4random()%256,arc4random()%256,arc4random()%256,1)];

        
        [self.windowaddSubview:myView1];

  

    //通过tag值得到对应的视图
    UIView *smallView = [self.windowviewWithTag:1004];

    

    //将得到的视图移动到最底层
    [self.windowsendSubviewToBack:smallView];

    //插入第几个位置
    [self.windowinsertSubview:smallView atIndex:0];
   }

    

    

    

    

    

    

    
    self.window.backgroundColor = [UIColorwhiteColor];
    [self.windowmakeKeyAndVisible];

   
    return YES;
}

//应用将要取消活跃状态,例如:我们正在玩游戏,如果来电话了或者来短信了,就会触发此方法。在此方法中一班我们是要讲游戏暂停,进行一些暂时操作、
- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS
message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

   //发送应用程序时将从活跃不活跃的状态。这可能发生某些类型的暂时中断(如电话来电或短信)或当用户退出应用程序开始转换到背景状态。//使用这种方法暂停正在进行的任务,禁用计时器,节流OpenGL
ES帧率。游戏应该使用这个方法来暂停游戏。
}

//程序已经进入后台,一般我们是要将一些重要数据进行保存,因为苹果手机应用进入后台之后,如果长时间不操作,应用就会退出。
- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current
state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

   //使用这个方法来释放共享资源,保存用户数据,无效计时器,和储存足够多的应用程序状态信息来恢复您的应用程序的当前状态情况下,终止。//如果您的应用程序支持后台执行,而不是调用此方法applicationWillTerminate:当用户退出。
}

//当应用程序进入前端的时候,会执行此代理方法
- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

  //称为部分从背景过渡到非活动状态,在这里你可以撤消的许多进入背景所做的更改
}

//程序进入前端之后,应用变得活跃,在此方法中,需要将刚才暂停的一些操作重新开启
- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user
interface.

    //重启任何任务暂停(或没有开始),而应用程序是不活跃的。如果应用程序在后台以前,可选更新用户界面
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    //程序将要退出时调用应用程序终止。如果适当的保存数据。参见applicationDidEnterBackground

}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ui 界面