问题描述
当设备的当前方向是面朝上或面朝下时,是否有可能将设备方向自动旋转到纵向?
[self presentViewController:[UIViewController new ] animated:NO completion:NULL];
[self dismissViewControllerAnimated:NO completion:NULL];
这将在您的控制器上调用 supportedInterfaceOrientations
。
当设备方向向上或向下,并且控制器的视图将相应调整时,只需返回 UIInterfaceOrientationMaskPortrait
/ p>
观察 设备和接口方向定义 Is there a possible way to autorotate the device orientation to portrait when the current orientation of the device is faceup or facedown? You can use this trick to make the system refresh your controller orientation anytime you want: This will call Just return Observe Device and interface orientation definitions: 这篇关于当当前方向为面朝上或面朝下时,如何将设备方向更改为纵向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! UIDeviceOrientationDidChangeNotification
s即可在收到通知时使用和是面向上/向下设备方向,因为这些方向不对应于 UIInterfaceOrientation
(并且不会触发
的typedef NS_ENUM(NSInteger的,UIInterfaceOrientation){
UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait,
UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight,
UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft
} ;
typedef NS_ENUM(NSInteger,UIDeviceOrientation){
UIDeviceOrientationUnknown,
UIDeviceOrientationPortrait,//垂直设备,底部的主页按钮
UIDeviceOrientationPortraitUpsideDown, ,home按钮在顶部
UIDeviceOrientationLandscapeLeft,//面向水平,主页按钮在右边
UIDeviceOrientationLandscapeRight,//面向水平,主页按钮左边
UIDeviceOrientationFaceUp,//面向设备flat,face up
UIDeviceOrientationFaceDown //面向设备的平面,面朝下
};
[self presentViewController:[UIViewController new] animated:NO completion:NULL];
[self dismissViewControllerAnimated:NO completion:NULL];
supportedInterfaceOrientations
on your controller.UIInterfaceOrientationMaskPortrait
when the device orientation is facing up or down and your controller's view will get adjusted accordingly.UIDeviceOrientationDidChangeNotification
s to use the trick when you receive the notification and it's a face up/down device orientation, as those orientation do not correspond to UIInterfaceOrientation
s (and won't trigger supportedInterfaceOrientations
).typedef NS_ENUM(NSInteger, UIInterfaceOrientation) {
UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait,
UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight,
UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft
};
typedef NS_ENUM(NSInteger, UIDeviceOrientation) {
UIDeviceOrientationUnknown,
UIDeviceOrientationPortrait, // Device oriented vertically, home button on the bottom
UIDeviceOrientationPortraitUpsideDown, // Device oriented vertically, home button on the top
UIDeviceOrientationLandscapeLeft, // Device oriented horizontally, home button on the right
UIDeviceOrientationLandscapeRight, // Device oriented horizontally, home button on the left
UIDeviceOrientationFaceUp, // Device oriented flat, face up
UIDeviceOrientationFaceDown // Device oriented flat, face down
};