今天項(xiàng)目中遇到正在看視頻的時(shí)候賬號被擠,如果當(dāng)時(shí)是橫屏的情況下,需要強(qiáng)制豎屏。真頭疼,網(wǎng)上找了好多方法,終于解決啦。O(∩_∩)O~
強(qiáng)制橫屏:
[self interfaceOrientation:UIInterfaceOrientationLandscapeRight];
強(qiáng)制豎屏:
[self interfaceOrientation:UIInterfaceOrientationPortrait];
強(qiáng)制轉(zhuǎn)屏
- (void)interfaceOrientation:(UIInterfaceOrientation)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;
// 從2開始是因?yàn)? 1 兩個(gè)參數(shù)已經(jīng)被selector和target占用
[invocation setArgument:&val atIndex:2];
[invocation invoke];
}
}