您的位置:首页 > 移动开发 > IOS开发

iOS中强制转换

2015-12-23 17:20 507 查看
iOS中强制转换

// 视图显示为横屏状态,温柔转换

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

return (interfaceOrientation ==
UIInterfaceOrientationLandscapeLeft);

}

-(BOOL)shouldAutorotate {

return
YES;

}

-(UIInterfaceOrientationMask)supportedInterfaceOrientations {

return
UIInterfaceOrientationMaskLandscapeLeft;

}

// 强制旋转

- (IBAction)tranfromOnClick:(UIButton *)sender

{

if ([UIDevice
currentDevice].orientation ==
UIDeviceOrientationPortrait)

{

[[UIDevice
currentDevice] setValue:[NSNumber
numberWithInteger:UIDeviceOrientationPortrait]
forKey:@"orientation"];//这句话是防止手动先把设备置为横屏,导致下面的语句失效.

[[UIDevice
currentDevice] setValue:[NSNumber
numberWithInteger:UIDeviceOrientationLandscapeLeft]
forKey:@"orientation"];

} else {

[[UIDevice
currentDevice] setValue:[NSNumber
numberWithInteger:UIDeviceOrientationLandscapeLeft]
forKey:@"orientation"];//这句话是防止手动先把设备置为竖屏,导致下面的语句失效.

[[UIDevice
currentDevice] setValue:[NSNumber
numberWithInteger:UIDeviceOrientationPortrait]
forKey:@"orientation"];

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: