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 關注
- 459 瀏覽
添加回答
舉報