特定页面实现旋转效果

1.在AppDelegate.h 里添加标记

2.在AppDelegate.m 里添加这个方法

3.打开屏幕旋转

[(AppDelegate*)[UIApplication sharedApplication].delegate setAllowRotation:YES];

 

4.取消屏幕旋转

    [(AppDelegate*)[UIApplication sharedApplication].delegate setAllowRotation:NO];

    [[NSNotificationCenter defaultCenterremoveObserver:self];

    if ([[UIDevice currentDevicerespondsToSelector:@selector(setOrientation:)]) {

        SEL selector = NSSelectorFromString(@"setOrientation:");

        NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDeviceinstanceMethodSignatureForSelector:selector]];

        [invocation setSelector:selector];

        [invocation setTarget:[UIDevice currentDevice]];

        int val = UIInterfaceOrientationPortrait;

        [invocation setArgument:&val atIndex:2];

        [invocation invoke];

    }

 

posted @ 2016-01-15 14:20  技术哥丶  阅读(206)  评论(0)    收藏  举报