我需要根据方向更改视图的图像背景.为此,我使用statusBarOrientation方法viewWillAppear:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
UIInterfaceOrientation currentOrientation = [[UIApplication sharedApplication] statusBarOrientation];
if (UIInterfaceOrientationIsPortrait(currentOrientation)) {
NSLog(@"PORTRAIT");
} else if (UIInterfaceOrientationIsLandscape(currentOrientation)) {
NSLog(@"LANDSCAPE");
}
}
Run Code Online (Sandbox Code Playgroud)
问题是控制台总是显示PORTRAIT,即使iPad处于横向模式.相同的代码viewDidAppear工作正常,但为时已晚,用户可以看到图像的变化.这让我觉得statusBarOrientation的正确状态仍然不可用viewWillAppear,但我已经读过其他一些问题,这段代码应该在那里工作.
只需将iOS 5应用程序更新到iOS 6,当然偶然发现了界面问题.我现在已经知道事情发生了变化,我甚至知道发生了什么变化,但我似乎无法自己管理.
我的应用程序包含几个viewcontrollers,它们被推送到一个navigationcontroller.所有的viewcontrollers都应该是横向的,除了一个应该是纵向的.在iOS 5中,一切工作正常,但现在纵向模式下的一个控制器也以横向模式显示,当然也会失真.
我的iOS 5代码看起来像这样:
Viewcontroller在横向模式下:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation==UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation==UIInterfaceOrientationLandscapeRight);
}
Run Code Online (Sandbox Code Playgroud)
Viewcontroller处于纵向模式:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return (interfaceOrientation==UIInterfaceOrientationPortrait) || (interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown);
}
Run Code Online (Sandbox Code Playgroud)
现在我发现了我实施的iOS 6中的变化
AppDelegate :(允许所有方向,如在plist中)
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
Run Code Online (Sandbox Code Playgroud)
横向模式下的Viewcontroller :(将方向限制为横向模式)
- (NSUInteger) supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
- (BOOL)shouldAutorotate{
return YES;
}
Run Code Online (Sandbox Code Playgroud)
纵向模式下的Viewcontroller :(将方向限制为纵向模式)
- (NSUInteger) supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait | UIInterfaceOrientationPortraitUpsideDown;
}
- …Run Code Online (Sandbox Code Playgroud) 我在浏览器中嵌入了Youtube视频,这是所有肖像应用程序的一部分.当您启动YouTube视频时,它将在MPAVController中播放并允许在Landscape中旋转.这对我来说不是问题,但问题是如果视频是横向的,我按"OK"关闭视频; 我返回浏览器,但iPhone状态栏现在停留在横向模式,在应用程序顶部留下一个空白区域,以及状态栏覆盖我的应用程序的右侧或左侧部分,具体取决于旋转方向.
包含UIWebView的视图控制器被纵向锁定:
- (BOOL) shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)
请注意,使用6.0之前的SDK进行编译时,不会出现此问题.
有类似问题的人有解决方案吗?
youtube iphone uiinterfaceorientation landscape-portrait ios6
帮我解决任务 - 我有一个不允许旋转其界面的viewController:
- (BOOL)shouldAutorotate {
return NO;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)
但我需要旋转出现在此控制器中的alertView!因此,如果用户旋转设备,则alertView应该跟随旋转并且主界面静止不动.我试图订阅通知:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceRotated:) name:UIDeviceOrientationDidChangeNotification object:nil];
Run Code Online (Sandbox Code Playgroud)
但在我的deviceRotated:收到通知中我有这样的负载:
NSConcreteNotification 0x101dc50 {name = UIDeviceOrientationDidChangeNotification; object = <UIDevice: 0x103e640>; userInfo = {
UIDeviceOrientationRotateAnimatedUserInfoKey = 1;
}}
什么是UIDeviceOrientationRotateAnimatedUserInfoKey?我如何使用知道当前的interfaceOrientation?或者建议一种更好的方法来获取当前方向并旋转alertView.
我试着用
(BOOL)shouldAutorotateToInterfaceOrientation:UIInterfaceOrientation)toInterfaceOrientation
和
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 但这些方法不会在iOS6上调用:(
此外,还有其他方法可以用来知道设备正在旋转到某个方向吗?提前致谢!PS我知道这个任务看起来有点傻,但这是客户的要求.抱歉:)
在我的工作应用程序(iOS 7.0.1)中,UIDeviceOrientationDidChangeNotification被调用.
现在,当我在iOS 8.0中运行此应用程序时,UIDeviceOrientationDidChangeNotification没有被调用.
尝试了很多,但没有运气.
编辑-1:
我使用下面的代码添加观察者的方向更改.适用于iOS 7,完美适用于iOS 8.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
Run Code Online (Sandbox Code Playgroud) 现在,interfaceOrientation属性格式中UIViewController已过时,什么是检测当前设备的方向推荐的方法是什么?
我目前正在开发适用于iOS 7+和XCode 6的SpriteKit游戏.游戏应始终以纵向模式呈现.到目前为止,我已在视图控制器中实现了这些方法:
- (BOOL)shouldAutorotate {
return NO;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
Run Code Online (Sandbox Code Playgroud)
只要我启动应用程序将我的iPad保持在纵向模式,这样就可以正常工作.在游戏过程中它不会切换方向.
但是,在应用程序启动期间以横向方向按住iPad时,游戏会以横向显示.
即使在启动期间设备以横向模式保持,如何强制应用程序以纵向模式显示?
orientation screen-orientation uiinterfaceorientation ios sprite-kit
我使用以下代码查看设备是否处于横向模式:
UIDevice.currentDevice().orientation.isLandscape.boolValue
Run Code Online (Sandbox Code Playgroud)
但是,如果我在启动应用程序之前将设备置于横向模式,则可以正常工作,之后再viewDidLoad调用此代码行,则始终返回false。
如果我改用这个:
interfaceOrientation.isLandscape
Run Code Online (Sandbox Code Playgroud)
它返回true,这是正确的,但是编译器正在显示警告interfaceOrientation was deprecated in iOS 8.0。
启动应用后立即获得设备定位的正确方法是什么?
我正在尝试.StartAnimating UIActivityIndicator当我旋转设备时,我试图使用覆盖函数:didRotateFromInterfaceOrientation; 但是,在旋转发生后调用此函数,我想在实际旋转期间进行动画处理.
我正在寻找一种在旋转时调用的方法.我查看了文献,并且发现了可能有用的折旧函数.
我现在可以使用任何方法吗?
我videoView在InterfaceBuilder的UIViewController中有一个自定义的UIView .
当我加载它,它看起来很好,但当我把它说成"从肖像景观"它不会去坐标告诉它的地方.然后,当我把它转回来时,它又错了.
我有以下代码:
-(void)viewWillAppear:(BOOL)animated
{
[self processRotation:self.interfaceOrientation];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
-(void)processRotation:(UIInterfaceOrientation)_interfaceOrientation
{
if (_interfaceOrientation == UIInterfaceOrientationLandscapeLeft || _interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
videoView.frame = CGRectMake(20.0f, 77.0f, 984.0f, 595.0f);
}
else if (_interfaceOrientation == UIInterfaceOrientationPortrait || _interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
videoView.frame = CGRectMake(20.0f, 297.0f, 728.0f, 453.0f);
}
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self processRotation:toInterfaceOrientation];
}
Run Code Online (Sandbox Code Playgroud) iphone objective-c uiviewcontroller uiview uiinterfaceorientation
ios ×7
ios6 ×3
iphone ×3
orientation ×3
swift ×3
objective-c ×2
ios8 ×1
sprite-kit ×1
swift2 ×1
swift3 ×1
uikit ×1
uistatusbar ×1
uiview ×1
youtube ×1