ui-uiwindow uiview

main

#import <UIKit/UIKit.h>
#import "AppDelegate.h"
//UIApplication对象:这是应用程序的象征,是iOS程序第一个创建的对象。每一个程序都有自己的UIApplication对象
//UIApplication对象的创建:[UIApplication sharedApplication],利用这个单例对象,能进行应用级别的操作

//UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]))
//第一个参数:argv数组元素的个数
//第二个参数:程序名(位置-沙盒)
//第三个参数:指定应用程序第一个类名,若为nil,则UIApplication类作为默认类(委托者)
//第四个参数:指定应用代理类AppDelegate class,应遵循UIApplicationDelegate协议

//UIApplicationMain作用
//1.主要是根据principalClassName和delegateClassName)来创建UIApplication对象和delegate对象,并将delegate对象赋值给UIApplication对象的delegate属性
//2.然后建立应用程序的Main Runloop(事件循环)
//3.程序正常退出后,UIApplicationMain函数才返回

int main(int argc, char * argv[]) {
    @autoreleasepool {
        [UIApplication sharedApplication];//利用这个单例创建UIApplication对象
        NSLog(@"%i",argc);//1个元素
        NSLog(@"%s",argv[0]);//沙盒位置
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

    }
}

AppDelegate.h

#import <UIKit/UIKit.h>
//UIApplicationDelegate遵循协议
//三者继承关系
//UIWindow:UIView:UIResponder

//iOS支持单一的窗口。
//UIWindow 是特殊的UIView,通常一个app只有一个UIWindow.
//iOS程序启动后,创建的第一个视图空间就是UIWindow。然后创建view...
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end

AppDelegate.m

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate
-(void)dealloc
{
    [super dealloc];
    _window = nil;
}
//循环事件
//测试-运行-home-进入程序
//2015-08-24 18:02:15.410 测试1[5754:150034] 程序启动完成
//2015-08-24 18:02:15.414 测试1[5754:150034] 进入活动状态(获取焦点)
//2015-08-24 18:02:35.603 测试1[5754:150034] 即将进入非活动状态(失去焦点,不能响应事件,例如打电话)
//2015-08-24 18:02:36.124 测试1[5754:150034] 进入后台(保存数据或者状态)
//2015-08-24 18:02:50.651 测试1[5754:150034] 即将从后台进入前台(恢复数据或状态)
//2015-08-24 18:02:51.161 测试1[5754:150034] 进入活动状态(获取焦点)
//2015-08-24 18:03:31.251 测试1[5754:150034] 即将进入非活动状态(失去焦点,不能响应事件,例如打电话)
//2015-08-24 18:03:31.779 测试1[5754:150034] 进入后台(保存数据或者状态)

#pragma make 1程序启动完成
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    NSLog(@"%s", __func__);
    NSLog(@"程序启动完成");
    //代码区
    //一个iOS程序之所以能显示在屏幕上,就是因为有UIWindow,否则就看不见任何UI控件
    //匹配屏幕大小[UIScreen mainScreen].bounds]
    self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor=[UIColor whiteColor];
    //将self.window在当前设备显示
    [self.window makeKeyAndVisible];
    UIView*view1=[[UIView alloc]initWithFrame:CGRectMake(100, 80, 100, 100)];
    view1.backgroundColor=[UIColor redColor];
    //将view1添加到window,引用计数器+1
    [self.window addSubview:view1];
    [view1 release];

    UIView*view2=[[UIView alloc]initWithFrame:CGRectMake(100, 200, 100, 100)];
    view2.backgroundColor=[UIColor greenColor];
    [self.window addSubview:view2];
    [view2 release];

    UIView*view3=[[UIView alloc]initWithFrame:CGRectMake(0, 310, 100, 100)];
    view3.backgroundColor=[UIColor yellowColor];
    [self.window addSubview:view3];
    [view3 release];

    UIView*view4=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
    view4.backgroundColor=[UIColor blueColor];
    [view3 addSubview:view4];
    [view4 release];

    UIView*view5=[[UIView alloc]initWithFrame:CGRectMake(20, 20, 50, 50)];
    view5.backgroundColor=[UIColor grayColor];
    [view3 addSubview:view5];
    [view5 release];

    UIView *view6 = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 100, 30)];
    view6.backgroundColor = [UIColor orangeColor];

    //查看多少个view;
    NSLog(@"%@",[self.window subviews]);

    //insertSubview
    //插入子视图到指定索引位置insertSubview
    [view3 insertSubview:view6 atIndex:1];
    //视图插入在指定视图之上
    [view3 insertSubview:view6 aboveSubview:view5];
    //视图插入在指定视图之下
    [view3 insertSubview:view6 belowSubview:view5];

    //exchangeSubviewAtIndex:withSubviewAtIndex:
    [view3 exchangeSubviewAtIndex:1 withSubviewAtIndex:2];

    //将视图移动到最上层bringSubviewToFront
    [view3 bringSubviewToFront:view4];
    //将视图移动到最下层sendSubviewToBack
    [view3 sendSubviewToBack:view4];

    //将所有子视图删除removeFromSuperview
    //子视图的父视图也被删除
    //[view3 removeFromSuperview];

    //隐藏
    view5.hidden=YES;

    //tag
    view3.tag=10;
    NSLog(@"%@",[view3 superview]);
    // <UIWindow: 0x7fb3d0d2c810; frame = (0 0; 375 667);
    NSLog(@"%@",[self.window viewWithTag:10]);
    //<UIView: 0x7f7fabd29cf0; frame = (0 310; 100 100); tag = 10; layer =

    //是否支持用户响应
    //view3.userInteractionEnabled=YES;

    //裁剪clipsToBounds
    view3.clipsToBounds=YES;

    //动画
    //1开始动画
    [UIView beginAnimations:nil context:nil];
    //2设置动画持续时间
    [UIView setAnimationDuration:3];
    //3动画内容
    CGRect frame=CGRectMake(view1.frame.origin.x+100, view1.frame.origin.y, view1.frame.size.width, view1.frame.size.height);
    view1.frame=frame;
    //4提交动画
    [UIView commitAnimations];

    //使用block实现动画
    [UIView animateWithDuration:3 animations:^{
        CGRect frame=CGRectMake(view1.frame.origin.x, view1.frame.origin.y+100, view1.frame.size.width, view1.frame.size.height);
        view1.frame=frame;
        //平移
        view3.transform=CGAffineTransformMakeTranslation(50, 100);
        //缩放
        view2.transform=CGAffineTransformMakeScale(0.5, 0.5);
        //旋转
        view3.transform=CGAffineTransformMakeRotation(M_PI);
    } completion:^(BOOL finished) {
        if(finished){
            NSLog(@"%@", NSStringFromCGRect(view2.frame));
            //            view1.hidden = YES;
            [UIView animateWithDuration:2 animations:^{
                view1.alpha = 0;
                view3.layer.cornerRadius = 50;
                view2.layer.cornerRadius = 50;
            }completion:nil];

        }
    }];

    return YES;
}

#pragma make 3即将进入非活动状态(失去焦点,不能响应事件,例如打电话)
- (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.
    NSLog(@"即将进入非活动状态(失去焦点,不能响应事件,例如打电话)");
}
#pragma make 4进入后台(保存数据或者状态)
- (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.
    NSLog(@"进入后台(保存数据或者状态)");
}
#pragma make 5即将从后台进入前台(恢复数据或状态)
- (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.
    NSLog(@"即将从后台进入前台(恢复数据或状态)");
}
#pragma make 2进入活动状态(获取焦点)
- (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.
    NSLog(@"进入活动状态(获取焦点)");
}
#pragma make 即将退出程序
- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    NSLog(@"即将退出程序");
}

#pragma make 内存过低时,发出内存警告(释放不必要的内存)
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
    NSLog(@"内存警告");
}

@end
时间: 2024-10-15 00:30:59

ui-uiwindow uiview的相关文章

UI 常用方法总结之--- UIWindow UIView (不断更新中)

 UIWindow (UIView) 1.创建一个uiwindow对象 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 2.backgroundColor 背景颜色 3.- (void)makeKeyAndVisible; eg: [self.window makeKeyAndVisible]; 设置这个window为主windows,并使其可见 4.rootViewController

iOS开发-UI (一)补充 UIWindow UIView UIlabel

之前忘了把这些整理出来,现在补充一下,应该放在前面学习的 知识点: 1.UI的初步认识 2.UIWindow 3.UIView 4.UIlabel ======================== UI的初步认识 1.什么是UI(*) UI即User Interface(用户界面)的简称.UI设计则是指对软 件的人机交互.操作逻辑.界面美观的整体设计.好的UI设 计不仅是让软件变得有个性有品味,还要让软件的操作变得 舒适.简单.自由.充分体现软件的定位和特点. 2.第一个UI工程 1)UI工程的

第一章 UI实战开发 UIWindow UIView

UI 即:用户界面   UIWindow的使用 用法 对UIWindow 进行初始化 IOS 程序的入口 -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { (self.window = [[UIWindow alloc] init ];//WithFrame:[UIScreen mainScreen].bounds];//创建w

UI第一讲.UIWindow UIView UILable 的基本使用

一.UIWindow 二.UIView 三.UILable

iOS开发UI—UIWindow介绍

一.简单介绍 UIWindow是一种特殊的UIView,通常在一个app中只会有一个UIWindow iOS程序启动完毕后,创建的第一个视图控件就是UIWindow,接着创建控制器的view,最后将控制器的view添加到UIWindow上,于是控制器的view就显示在屏幕上了 一个iOS程序之所以能显示到屏幕上,完全是因为它有UIWindow.也就说,没有UIWindow,就看不见任何UI界面 补充:UIWindow是创建的第一个视图控件(创建的第一个对象是UIapplication)如下图:

UI 初识UIView

1.UIWindow App靠window来呈现内容,?个程序?般只创建?个window. 通常window的??(frame)与屏幕(UIScreen)???致. ?例代码如下: self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; _window.backgroundColor = [UIColor whiteColor];    // 视图的添加写在这里    [_window makeKe

IOS开发UI基础UIView

主要介绍下UIView得基本概念和一些属性的介绍至于属性的用户后面会由详细的介绍 -.UIView基本概念 1.什么是控件? 屏幕上所有的UI元素都叫做控件 (也有很多书中叫做视图 组件) 比如 按钮(UIButton) 文本(UILabel)都是控件 控件的共同属性有哪些? 尺寸 位置 背景色 ........... 苹果将控件的共同属性都抽取到父类UIView中 所有的控件最终都继承自UIView中 UIBUtton UIView都继承自UIView 父控件.子控件 每个控件都是个容器 能够

UI开发----UIView和UILable

//  Created By 郭仔  2015年04月10日17:48:32 今天还要买两张票,周天回家周天在回来!不管什么事,请记住:  有我在!!! 祝:天佑郭家!!! ========================================================================== Window窗口: window是窗?口,每个app都需要借助window将内容展现给?用户看. 在iOS中,使?用UIWindow类来表?示窗?口,通常?一个应?用程序只创建

UI基础UIView常见属性及方法

1.NSBundle 1> 一个NSBundle代表一个文件夹,利用NSBundle能访问对应的文件夹 2> 利用mainBundle就可以访问软件资源包中的任何资源 3> 模拟器应用程序的安装路径 /Users/aplle/资源库/Application Support/iPhone Simulator/7.1/Applications 2.UIImageView和UIButton 1> 使用场合 * UIImageView: 如果仅仅是显示图片,不需要监听图片的点击 * UIB

UI基础-UIView

UIView的常见属性 NSArray *subviews 所有的子控件 数组元素的顺序决定着子控件的显示层级顺序(下标越大的,越显示在上面) UIView的常见方法 addSubview: 添加一个子控件 使用这个方法添加的子控件会被塞到subviews数组的最后面 可以使用下面的方法调整子控件在subview数组中的顺序 // 将子控件view插入到subviews数组的index位置 - (void)insertSubview:(UIView *)view atIndex:(NSInteg