美文网首页iOS大咖说
iOS -切换设备方向

iOS -切换设备方向

作者: 歌白梨 | 来源:发表于2016-08-16 20:16 被阅读98次

方法:

- (void)changeToOrientation:(UIDeviceOrientation)orientation
{
    if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
        SEL selector = NSSelectorFromString(@"setOrientation:");
        NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
        [invocation setSelector:selector];
        [invocation setTarget:[UIDevice currentDevice]];
        int val = orientation;
        [invocation setArgument:&val atIndex:2];
        [invocation invoke];
    }
}

调用:

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
} __TVOS_PROHIBITED;

 
[self changeToOrientation:UIDeviceOrientationPortrait];

相关文章

  • iOS -切换设备方向

    方法: 调用:

  • iOS屏幕旋转(横竖屏)

    一、屏幕旋转方向监听 1、UIDeviceOrientation:设备方向 iOS 定义了七种设备方向: 当设备方...

  • iOS 切换横竖屏

    参照:iOS强制转换横竖屏和键盘方向控制 实现点击按钮切换横竖屏的功能,设备锁屏无影响。效果如图所示: 然后,就是...

  • 关于ipad支持横屏旋转

    加速计是整个IOS屏幕旋转的基础,依赖加速计,设备才可以判断出当前的设备方向,IOS系统共定义了以下七种设备方向:...

  • iOS 获取设备方向

    方法一:UIInterfaceOrientation orientation = [UIApplication s...

  • iOS--设备方向

    Device OrientationPortrait 竖屏正向Upside Down...

  • LibGDX输入模块之罗盘

    一些Android设备和iOS设备有一个集成的磁场传感器,提供有关器件获取北极方向的信息。 注意:目前在iOS设备...

  • unity 陀螺仪判断手机方向

    首先说一下为什么用陀螺仪,很多时候当ios设备系统级别锁定方向后,我们使用ios系统的设备方向方法将不能其作用。 ...

  • iOS 11设备上UIViewController切换时Tabl

    最近遇到项目在iOS 11设备上UIViewController切换时TableView会异常的向下偏移,随着界面...

  • Flutter教程app

    前言 使用Flutter开发Flutter教程,<-_<-有点意思! 功能 夜间模式、文字大小、文字方向、设备切换...

网友评论

    本文标题:iOS -切换设备方向

    本文链接:https://www.haomeiwen.com/subject/nygpsttx.html