zoukankan      html  css  js  c++  java
  • Note of IOS 7

    1. Views

    presentation:

    A view (an object whose class is UIView or a subclass of UIView) knows how to draw itself into a rectangular area of the interface.

    eg: you can drag an interface widget, such as a UIButton, into a view in the nib editor; when the app runs, the button appears, and works properly.

    interact:

    A view is also a responder (UIView is a subclass of UIResponder).
    This means that a view is subject to user interactions, such as taps(轻敲) and swipes(猛击).
    Thus, views are the basis not only of the interface that the user sees,
    but also of the interface that the user touches.

    A view may come from a nib, or you can create it in code. On balance, neither approach
    is to be preferred over the other; it depends on your needs and inclinations(倾向) and on the
    overall architecture of your app.

    2. The Window

    The top of the view hierarchy is the app’s window.

    It is an instance of UIWindow, which is a UIView subclass. Your app should have exactly one main window.

    It is created at launch time and is never destroyed or replaced.

    It occupies the entire screen and forms the background to, and is the ultimate superview of, all your other visible views.

    The window must fill the device’s screen.

    Therefore, its size and position must be identical to the size and position of the screen.

    This is done by setting the window’s frame to the screen’s bounds as the window is instantiated.

    eg:

    UIWindow* w = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    The window must persist for the lifetime of the app. To make this happen, the app
    delegate class has been given a window property with a strong retain policy.

    App without a main storyboard

    If your app has no main storyboard, then creation and configuration of the window
    must be done in some other way. Typically, it is done in code.

    in application:didFinishLaunchingWithOptions:, like this:

    self.window =
    [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];

    You can drag a view from the Object library into the main view as a subview,
    and it will be instantiated in the interface when the app runs.

    Alternatively, you can create views and add them to the interface in code;

    the simplest place to do this, for now, is the view controller’s viewDidLoad method, which has a reference to the view controller’s
    main view as self.view.

    eg:

    - (void)viewDidLoad {
      [super viewDidLoad];
      UIView* mainview = self.view;
      UIView* v = [[UIView alloc] initWithFrame:CGRectMake(100,100,50,50)];
      v.backgroundColor = [UIColor redColor]; // small red square
      [mainview addSubview: v]; // add it to main view
    }

    Alternatively, you can start your project with the Empty Application template. It has
    no .xib or .storyboard file, so your views will have to be created entirely in code. The
    Empty Application template does not supply any view controllers, and does not assign
    any view controller to the window’s rootViewController property.

    A simple solution is to put your code in the app delegate’s application:didFinishLaunchingWithOptions:,

    creating a minimal root view controller and accessing its main view through its view property.

    eg: 

    - (BOOL)application:(UIApplication *)application
      didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
      
      // (template code:)
      self.window =
        [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
     
      // Override point for customization after application launch.
      // (your code:)
      self.window.rootViewController = [UIViewController new];
      UIView* mainview = self.window.rootViewController.view;
      UIView* v = [[UIView alloc] initWithFrame:CGRectMake(100,100,50,50)];
      v.backgroundColor = [UIColor redColor]; // small red square
      [mainview addSubview: v]; // add it to the main view
      
      // (template code:)
      self.window.backgroundColor = [UIColor whiteColor];
      [self.window makeKeyAndVisible];
      
      return YES;
    }

    The method addSubview: makes one view a subview of another;

    removeFromSuperview takes a subview out of its superview’s view hierarchy.

    Oddly, there is no command for removing all of a view’s subviews at once.

    However, a view’s subviews array is an immutable copy of the internal list of subviews, so it is legal
    to cycle through it and remove each subview one at a time:

    for (UIView* v in view.subviews)
      [v removeFromSuperview];

     Here’s an alternative way to do that:

    [view.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];

    3. Frame

    A view’s frame property, a CGRect, is the position of its rectangle within its superview,
    in the superview’s coordinate system.

    UIView* v1 = [[UIView alloc] initWithFrame:CGRectMake(113, 111, 132,   194)];
    v1.backgroundColor = [UIColor colorWithRed:1 green:.4 blue:1 alpha:1];
    
    UIView* v2 = [[UIView alloc] initWithFrame:CGRectMake(41, 56, 132, 194)];
    v2.backgroundColor = [UIColor colorWithRed:.5 green:1 blue:0 alpha:1];
    
    UIView* v3 = [[UIView alloc] initWithFrame:CGRectMake(43, 197, 160, 230)];
    v3.backgroundColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
    
    [mainview addSubview: v1];
    [v1 addSubview: v2];
    [mainview addSubview: v3];


    运行如下:

  • 相关阅读:
    xtu summer individual 6 B
    Docker和宿主机操作系统文件目录互相隔离的实现原理
    SAP成都研究院飞机哥: SAP C4C中国本地化之微信聊天机器人的集成
    C4C销售订单行项目价格维护方法
    Jerry Wang诚邀广大SAP同仁免费加入我的知识星球,共同探讨SAP技术问题
    为什么CRM Opportunity的删除会触发一个通向BW系统的RFC
    如何用代码填充S/4HANA销售订单行项目的数量字段
    SAP成都研究院大卫哥:SAP C4C中国本地化之微信小程序集成
    如何获得C4C里某个code字段对应的描述信息
    如何用代码的方式取出SAP C4C销售订单创建后所有业务伙伴的数据
  • 原文地址:https://www.cnblogs.com/davidgu/p/3541290.html
Copyright © 2011-2022 走看看