mirror of
https://gh-proxy.org/https://github.com/klinsmaya/dashjim.github.com.git
synced 2026-11-08 01:16:54 +08:00
调整
This commit is contained in:
@@ -9,13 +9,18 @@ tags:
|
||||
---
|
||||
|
||||
|
||||
####一.UISupportedInterfaceOrientations
|
||||
### 一.UISupportedInterfaceOrientations
|
||||
|
||||
这个UIKit的设定可以通过XCode工具来设定.
|
||||
这个UIKit的设定可以通过XCode工具来设定.
|
||||
<br>
|
||||

|
||||
或者直接编辑info plist
|
||||
<br>
|
||||
|
||||
或者直接编辑info plist
|
||||
<br>
|
||||

|
||||
|
||||
<br>
|
||||
|
||||
对应的是一个数组,可以有以下几种类型
|
||||
UIInterfaceOrientationPortrait
|
||||
UIInterfaceOrientationPortraitUpsideDown
|
||||
@@ -24,12 +29,12 @@ UIInterfaceOrientationLandscapeRight
|
||||
那UISupportedInterfaceOrientations的作用是什么呢?
|
||||
系统会根据UISupportedInterfaceOrientations支持的取向结合设备的当前取向来决定程序启动时的初始取向.
|
||||
|
||||
#### 二.UIViewController's Interface Orientation
|
||||
### 二.UIViewController's Interface Orientation
|
||||
|
||||
当设备的取向发生变化的时候,系统会发送UIDeviceOrientationDidChangeNotification通知,一般情况下我们自己不必亲自处理此通知,因为UIKit框架已经获取通知并做处理了。
|
||||
有一点需要注意的是,不管什么取向,UIWindow的frame始终是不会变化的,可以认为其始终是Portrait的取向。还有就是当app启动的时候,UIViewController 都会从Portrait取向转到当前的取向。
|
||||
|
||||
##### 1.声明UIViewController所支持的取向
|
||||
#### 1.声明UIViewController所支持的取向
|
||||
|
||||
{% highlight objc%}
|
||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation
|
||||
@@ -44,7 +49,7 @@ UIInterfaceOrientationLandscapeRight
|
||||
|
||||
返回YES,则说明当前UIViewController支持此orientation,返回NO则不支持此orientation
|
||||
|
||||
##### 2.One-part Rotation
|
||||
#### 2.One-part Rotation
|
||||
UIViewController 有几个方法可以让子类来覆盖
|
||||
{% highlight objc%}
|
||||
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
|
||||
@@ -68,18 +73,22 @@ UIViewController 有几个方法可以让子类来覆盖
|
||||
为了探究在UIViewController旋转的过程中到底发生了什么,可以新建一个Single View的项目用来测试。
|
||||
ViewController设置为UIWindow的rootViewController.当旋转的时候rootViewController旋转相关的方法会被调用,且rootViewController的view会发生旋转。
|
||||
假设程序启动时,app的取向是Portrait,即如下图所示
|
||||
<br>
|
||||

|
||||
|
||||
<br>
|
||||
当旋转,运行到willAnimateRotationToInterfaceOrientation之时,其view的bounds已是新的,只是其frame此时为(0 0; 300 480),不过view本身的transform为旋转90度的变换(transform = [0, 1, -1, 0, 0, 0]),且view有animates相附,
|
||||
{% highlight objc%}
|
||||
animations = { transform=<CABasicAnimation: 0x6a79840>; position=<CABasicAnimation:
|
||||
0x6a91fa0>; bounds=<CABasicAnimation: 0x6a920e0>; };
|
||||
{% endhighlight %}
|
||||
可知其位置和bounds都有相关动画。
|
||||
|
||||
<br>
|
||||

|
||||
<br>
|
||||
|
||||
旋转结束之后为如下样子
|
||||
旋转结束之后为如下样子
|
||||
view的frame是(0 0; 300 480),只是进行了transform,且依据AutoresingMask进行了调整
|
||||
<br>
|
||||

|
||||
|
||||
<br>
|
||||
只有知道旋转的本质之后,很多事情理解起来就深刻多了。
|
||||
Reference in New Issue
Block a user