3 回答
TA贡献1891条经验 获得超3个赞
对于iOS 7和8:
目标C:
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
迅捷3+:
let value = UIInterfaceOrientation.landscapeLeft.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
我叫它- viewDidAppear:。
TA贡献1876条经验 获得超7个赞
用这个。定向问题的完美解决方案..ios7和更早版本
[[UIDevice currentDevice] setValue:
[NSNumber numberWithInteger: UIInterfaceOrientationPortrait]
forKey:@"orientation"];
TA贡献1833条经验 获得超4个赞
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft]; [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
确实可以,但是您必须在视图控制器中返回shouldAutorotate并使用YES
- (BOOL)shouldAutorotate
{
return self.shouldAutoRotate;
}
但是,如果这样做,如果用户旋转设备,VC将自动旋转...因此我将其更改为:
@property (nonatomic, assign) BOOL shouldAutoRotate;
- (BOOL)shouldAutorotate
{
return self.shouldAutoRotate;
}
我打电话
- (void)swithInterfaceOrientation:(UIInterfaceOrientation)orientation
{
self.rootVC.shouldAutoRotate = YES;
NSNumber *value = [NSNumber numberWithInt: orientation];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}
单击按钮以强制新的方向。要将shouldAutoRotate设置为NO,我将其添加到了rootVC
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
self.shouldAutoRotate = NO;
}
PS:此替代方法也适用于所有模拟器。
- 3 回答
- 0 关注
- 426 浏览
添加回答
举报