关于UIDeviceOrientation和UIInterfaceOrientation |
02 |
03 | 1,UIDeviceOrientation 是设备的方向,只能读取不能设置,支持6个方向, |
04 | 的 typedef 的 NS_ENUM(NSInteger的, UIDeviceOrientation ) { |
05 | UIDeviceOrientationUnknown , |
06 | UIDeviceOrientationPortrait , //设备垂直方向,在底部的home键 |
07 | UIDeviceOrientationPortraitUpsideDown, 垂直方向,home键的顶部 |
08 | UIDeviceOrientationLandscapeLeft, //设备水平方向,home键在右边 |
09 | UIDeviceOrientationLandscapeRight, //设备水平方向,home键在左侧 |
10 | UIDeviceOrientationFaceUp, //设备面向平板,正视 |
11 |
12 | UIDeviceOrientationFaceDown //面向平板设备,脸朝下 |
13 |
14 | }; |
15 |
16 |
17 |
18 | UIInterfaceOrientation是软件的方向,可以读取可以设置。 |
19 | 的 typedef 的 NS_ENUM(NSInteger的, UIInterfaceOrientation ) { |
20 | UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait, |
21 | UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown, |
22 | UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight |
23 | UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft |
24 |
25 | }; |
26 |
27 | 注意:UIInterfaceOrientation的横屏的左边和右边跟UIDeviceOrientation刚好相反。 |
28 |
29 | 2、如果需要获取设备方向变化(UIDeviceOrientation)的消息的话,需要注册UIDeviceOrientationDidChangeNotification通知。 |
30 |
31 | 在注册通知时,需要先调用UIDevice的beginGeneratingDeviceOrientationNotifications方法 |
32 |
33 | [[ UIDevice currentDevice ] beginGeneratingDeviceOrientationNotifications ]; |
34 |
35 | [notificationCenter addObserver:self selector:@selector(deviceOrientationDidChange) name:UIDeviceOrientationDidChangeNotification object:nil]; |
36 |
37 | 同时,在结束时,需要移除改通知消息 |
38 | [ notificationCenter removeObserver :自的 名称: UIDeviceOrientationDidChangeNotification 对象:无]; |
39 |
40 | [[ UIDevice currentDevice ] endGeneratingDeviceOrientationNotifications ]; |