UI_視圖界面

#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];

    

    

    //得到myViewframe,並將它轉換爲字符串類型

    NSString *frame = NSStringFromCGRect(myView.frame);

    

    //得到myViewbounds,並將它轉換爲字符串類型

    NSString *bounds =NSStringFromCGRect(myView.bounds);

    

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

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

    

    

    //改變一下bounds的值.frame參照的是父視圖的座標系,意思是說,framemyView在父視圖的位置的體現。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));

    

    

    //centerOC語言下,調用屬性方法的點語法;

    //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


發佈了23 篇原創文章 · 獲贊 0 · 訪問量 5124
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章