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(,,,)];
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(,,,)];
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(, , ,   )];
v1.backgroundColor = [UIColor colorWithRed: green:. blue: alpha:]; UIView* v2 = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
v2.backgroundColor = [UIColor colorWithRed:. green: blue: alpha:]; UIView* v3 = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
v3.backgroundColor = [UIColor colorWithRed: green: blue: alpha:]; [mainview addSubview: v1];
[v1 addSubview: v2];
[mainview addSubview: v3];

运行如下:

Note of IOS 7 - Views的更多相关文章

  1. Collection View Programming Guide for iOS---(一)----About iOS Collection Views

    Next About iOS Collection Views 关于iOS Collection Views A collection view is a way to present an orde ...

  2. iOS Programming Views :Redrawing and UIScrollView

    iOS Programming Views :Redrawing and UIScrollView  1.1 event  You are going to see how views are red ...

  3. iOS Programming - Views(视图 - 基本绘制,变换,平移,旋转,反转,倾斜)

    1. Views A view (an object whose class is UIView or a subclass of UIView) knows how to draw itself i ...

  4. iOS学习笔记(6)——翻译苹果文档About Windows and Views

    About Windows and Views 关于窗口和视图 In iOS, you use windows and views to present your application’s cont ...

  5. iOS 9的新内容

    https://www.hackingwithswift.com/ios9 Search extensibility Update: I wrote a tutorial on Core Spotli ...

  6. Project support for both iOS 6 and iOS 7

    原文:https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TransitionGuide/S ...

  7. Scoping the Project for iOS 7

    Scoping the Project On This Page Things Every App Must Do Things Every App Should Do If You Must Con ...

  8. iOS 7 UI 过渡指南 - 支持续 iOS 6(iOS 7 UI Transition Guide - Supporting iOS 6)

    iOS 7 UI Transition Guide Preparing for Transition Before You Start Scoping the Project Supporting i ...

  9. IOS 开发教程

    http://www.raywenderlich.com/category/ios http://www.raywenderlich.com/50310/storyboards-tutorial-in ...

随机推荐

  1. Pacman主题下给Hexo增加简历类型

    原文 http://blog.zanlabs.com/2015/01/02/add-resume-type-to-hexo-under-pacman-theme/ 背景 虽然暂时不找工作,但是想着简历 ...

  2. [Everyday Mathematics]20150107

    设 $f\in C^1[a,b]$, $f(a)=0$, 且存在 $\lm>0$, 使得 $$\bex |f'(x)|\leq \lm |f(x)|,\quad \forall\ x\in [a ...

  3. [Everyday Mathematics]20150105

    设 $f\in C^1(a,b)$ 适合 $$\bex \lim_{x\to a^+}f(x)=+\infty,\quad \lim_{x\to b^-}f(x)=-\infty, \eex$$ 并且 ...

  4. Maximum Product Subarray JAVA实现

    题目描述: Find the contiguous subarray within an array (containing at least one number) which has the la ...

  5. Android http协议实现文件下载

    用http协议下载文件,主要用到的是httpURLConnection对象,主要的步骤如下: 1. 创建HttpURLConnection对象 2.获得一个InputStream对象 3.修改权限:访 ...

  6. JVM 性能调优实战之:使用阿里开源工具 TProfiler 在海量业务代码中精确定位性能代码

    本文是<JVM 性能调优实战之:一次系统性能瓶颈的寻找过程> 的后续篇,该篇介绍了如何使用 JDK 自身提供的工具进行 JVM 调优将 TPS 由 2.5 提升到 20 (提升了 7 倍) ...

  7. linux命令——rm

    rm是常用的命令,该命令的功能为删除一个目录中的一个或多个文件或目录,它也可以将某个目录及其下的所有文件及子目录均删除.对于链接文件,只是删除了链接,原有文件均保持不变. rm是一个危险的命令,使用的 ...

  8. Web自动化框架之五一套完整demo的点点滴滴(excel功能案例参数化+业务功能分层设计+mysql数据存储封装+截图+日志+测试报告+对接缺陷管理系统+自动编译部署环境+自动验证false、error案例)

    标题很大,想说的很多,不知道从那开始~~直接步入正题吧 个人也是由于公司的人员的现状和项目的特殊情况,今年年中后开始折腾web自动化这块:整这个原因很简单,就是想能让自己偷点懒.也让减轻一点同事的苦力 ...

  9. <转>详解DNS的常用记录(下):DNS系列之三

    在上篇博文中我们介绍了DNS服务器中几种不可或缺的记录,包括A记录,NS记录和SOA记录.本篇博文中我们将继续为大家介绍DNS的另外几种常用记录,希望能对大家了解DNS有所帮助. 四 MX记录 MX记 ...

  10. C++实现网格水印之调试笔记(六)—— 提取完成

    昨天在修改了可以调试出来的错误之后,提取出的水印和嵌入的仍然相去甚远.这个时候我觉得有必要整理一下嵌入和提取的整个过程. 嵌入过程: Step1,嵌入的时候对网格的拉普拉斯矩阵L进行特征值分解,得到特 ...