【发布时间】:2017-12-13 19:49:04
【问题描述】:
我需要像 Youtube 的全屏一样修复方向纵向或横向。 当用户单击按钮时,它被更改为纵向或横向。 并被修复。 用户只能通过按钮进行控制。
一般接受设备方向纵向、横向左侧 这是我的代码
AppDelegate
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
if(restrictRotation)
return UIInterfaceOrientationMaskPortrait;
else
return UIInterfaceOrientationMaskLandscapeLeft;
}
视图控制器
-(void) restrictRotation:(BOOL) restriction
{
AppDelegate* appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
appDelegate->restrictRotation = restriction;
}
- (IBAction)rotateOrientationAction:(id)sender
{
[self restrictRotation:NO];
if(isPortrait){
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationLandscapeLeft) forKey:@"orientation"];
self.myNewScrollViewHeight.constant = self.view.frame.size.height - self.naviBar.frame.size.height - self.horizMenu.frame.size.height;
self.portraitMenuView.hidden = YES;
}else{
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortrait) forKey:@"orientation"];
self.myNewScrollViewHeight.constant = self.view.frame.size.height * 0.5;
self.portraitMenuView.hidden = NO;
}
isPortrait = !isPortrait;
[self restrictRotation:YES];
}
如果我点击按钮,它会被更改为横向,但不会再次更改纵向。
谢谢
【问题讨论】:
-
你尝试过什么,分享一下代码,你遇到了什么困难。
-
编辑代码谢谢
标签: ios objective-c iphone