标签: uiinterfaceorientation

如何处理UIDeviceOrientationFaceUp和UIDeviceOrientationFaceDown?

这里有一个菜鸟问题.

我用以下方法检测方向:

UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];

一切都很好,花花公子,我根据报告的方向重新定位我的文本字段和标签

if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown)

而其他一切都是{}

我最近才发现的问题是当UIDevice报告UIDeviceOrientationFaceUpUIDeviceOrientationFaceDown.我该如何处理这种情况?我怎么知道是否UIDeviceOrientationFaceUpUIDeviceOrientationFaceDown纵向或横向是怎么回事?我知道设备正朝上或朝下,但我不知道是否应该将所有内容重新定位为纵向或横向.

谢谢!

uidevice uiinterfaceorientation ios

19
推荐指数
1
解决办法
6623
查看次数

启用页面并更改设备旋转/方向的UIScrollView(MADNESS)

我很难做到这一点.

我有一个UIScrollView,启用了分页.它由视图控制器(MainViewController)管理,每个页面由PageViewController管理,其视图作为scrollView的子视图添加到适当的偏移量.滚动是左右,适用于标准方向的iPhone应用程序.效果很好.基本上就像Apple提供的样本一样,也像iPhone提供的Weather应用程序一样.

但是,当我试图支持其他方向时,事情并不能很好地发挥作用.我用这种方法支持MainViewController和PageViewController中的每个方向:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
     return YES;
}
Run Code Online (Sandbox Code Playgroud)

然而,当我旋转设备时,我的页面变得非常歪斜,并且有很多绘图故障,特别是如果只加载了一些页面,然后我旋转,然后滚动更多等等...非常凌乱.

我告诉我的观点是支持自动调整大小

 theView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
Run Code Online (Sandbox Code Playgroud)

但无济于事.它似乎只会拉伸和歪曲我的观点.

在我的MainViewController中,我添加了这一行,试图调整我所有页面的视图:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * ([self.viewControllers count]), self.scrollView.frame.size.height);

    for (int i = 0; i < [self.viewControllers count]; i++) {
        PageViewController *controller = [self.viewControllers objectAtIndex:i];
        if ((NSNull *)controller == [NSNull null])
            continue;

        NSLog(@"Changing frame: %d", i);
        CGRect frame = self.scrollView.frame;
        frame.origin.x = frame.size.width * i;
        frame.origin.y = 0;
        controller.view.frame = frame;
    }
}
Run Code Online (Sandbox Code Playgroud)

但它没有太多帮助(因为我懒得加载视图,所以当执行时不一定都会加载它们).

有什么方法可以解决这个问题吗?

cocoa-touch objective-c uiscrollview uiinterfaceorientation ios

18
推荐指数
1
解决办法
1万
查看次数

如何检测iPad上启动画面动画的应用启动方向!

嗨,我有一个应用程序,我有两个*.pngs默认闪屏:

Default-Landscape.png Default-Portrait.png

我想要的是在我的应用程序加载并准备好时,将此默认启动画面设置为动画.

为了达到这个目的,我通常会使用默认横向或默认纵向(取决于设备方向)呈现UIImageView,将其保留在屏幕上一段时间,然后将其设置为动画.

我的问题是,如果我呼吁[[UIDevice currentDevice] orientation]

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
Run Code Online (Sandbox Code Playgroud)

答案始终是设备处于纵向方向,即使我清楚地将其置于风景中.我在模拟器和设备上尝试了这个,行为是一样的.

有没有人知道这个或其他方法的解决方案?

谢谢!

iphone uikit uidevice uiinterfaceorientation device-orientation

18
推荐指数
2
解决办法
1万
查看次数

状态栏为横向,但[[UIApplication sharedApplication] statusBarOrientation]返回纵向

这个问题似乎是间歇性的,但我不确定为什么.在设备(iPad)上运行我的应用程序时,我有一些代码可以根据当前设备方向加载带有一些图像视图的滚动视图.即使设备在加载之前是横向的,视图也会像纵向一样被加载.

通过调用找到方向[[UIApplication sharedApplication] statusBarOrientation].

视图设置为在旋转设备时调整其位置,实际上,旋转到纵向然后返回到横向将它们返回到正确的横向位置.是否所有应用程序都以纵向方式开始,如果需要,很快就会更改为横向?我是否试图过早检查方向(在init第一个视图控制器加载期间)?

orientation ipad uiinterfaceorientation ios

16
推荐指数
2
解决办法
4万
查看次数

UINavigation视图和UITabbar视图在iOS6中不起作用?

我在ios 6中创建了一个带有导航视图的应用程序.我也在应用程序摘要中设置了所有方向选项,甚至使用了

 -(BOOL) shouldAutoRotate
Run Code Online (Sandbox Code Playgroud)

-(NSUInteger) supportedInterfaceOrientaion
Run Code Online (Sandbox Code Playgroud)

在我的视图控制器中的方法.当我运行我的应用程序方向工作正常,除了颠倒.我应该做什么也支持倒置.

当我添加UITabBar控制器时,我也遇到了同样的问题.

请分享您的想法.

谢谢

iphone uinavigationcontroller uiinterfaceorientation ios6

16
推荐指数
1
解决办法
3545
查看次数

在模态视图之后保持父视图的方向呈现不同的方向

所以我正在开发一个仅支持横向模式的iPad应用程序,除了在一个模态视图控制器上.我遇到的问题是,一旦我呈现模态视图并将方向更改为纵向然后关闭视图,父视图(应该只支持横向)处于纵向模式,直到我旋转设备然后返回到风景和保持这种方式.我一直在努力弄清楚如何让父母保持原始方向,但却未能找到解决方案.

我在我的app委托中有以下代码,只允许在单个模态视图(GalleryPhotoViewer)上进行方向更改:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
NSUInteger orientations = UIInterfaceOrientationMaskAllButUpsideDown;

    if(self.window.rootViewController){
        UIViewController *presentedViewController = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject];

        //Support Portrait mode only on Photoviewer
        if ([[presentedViewController presentedViewController] isKindOfClass:GalleryPhotoViewController.class] ) {
            orientations = UIInterfaceOrientationMaskAll;
        }else{
            orientations = [presentedViewController supportedInterfaceOrientations];

        }
    }

    return orientations;
}
Run Code Online (Sandbox Code Playgroud)

从父类(PhotosViewController)我调用:

GalleryPhotoViewController *gpView = [GalleryPhotoViewController new];
[self presentViewController:gpView animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

在我的父(以及其他视图)中,我有以下代码禁止纵向模式:

- (NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if(interfaceOrientation == UIInterfaceOrientationPortrait) {
       return YES;
    } else {
        return NO;
    }
}
Run Code Online (Sandbox Code Playgroud)

关于如何在我的父视图上保持方向的任何想法?一旦模态被解除,我在考虑可能只是以编程方式更改viewWillAppear方法中父级的方向,但后来我不知道之前的方向是什么,更不用说我无法找到代码来执行此操作不管是ios6.

编辑/解决方案:所以我找到了一个解决方案,我最终做的是离开应用程序:supportedInterfaceOrientationsForWindow:代码,只是将UINavigation子类添加到呈现模态视图的父视图中,并且所有内容都按预期工作,父级保留其原始在模态能够自由变化的同时取向. …

ipad uiinterfaceorientation modalviewcontroller ios ios6

16
推荐指数
1
解决办法
4730
查看次数

在方向更改时动画UICollectionView

考虑一个UICollectionView,它在横向和纵向方向上具有不同数量的项目和不同的布局(即:间距).

当设备旋转时,需要做些什么才能对这些更改进行动画处理?我在" 收集视图编程指南"中找不到如何处理旋转的任何提及.

iphone uiinterfaceorientation ios uicollectionview

15
推荐指数
3
解决办法
2万
查看次数

适当的AutoresizingMask

我有一个视图出现在其父视图肖像模式的中心,我应该使用什么autoresizemask,以便它也以横向模式显示在中心.它的大小应该保持不变.我只是希望它的原点应该在这一点自动移动,以便它出现在中心.有什么帮助吗?

我给了

[parentView setAutoResizesSubview:YES];

parentView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
Run Code Online (Sandbox Code Playgroud)

uiview uiinterfaceorientation ios autoresizingmask

14
推荐指数
1
解决办法
1万
查看次数

在全屏幕上强制横向方向MPMoviePlayerController在退出全屏时阻止正确旋转

我有一个支持所有界面方向的iPhone应用程序(iOS6 +).但是,当MPMoviePlayerController正在播放全屏视频时,应仅支持横向.

我在Stack Overflow上找到了以下解决方案,它可以工作.

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillEnterFullscreenNotification:) name:MPMoviePlayerWillEnterFullscreenNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerWillExitFullscreenNotification:) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
Run Code Online (Sandbox Code Playgroud)

...

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
    if (self.landscapeOnlyOrientation) {
        return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
    }
    return UIInterfaceOrientationMaskAll;
}

- (void)moviePlayerWillEnterFullscreenNotification:(NSNotification*)notification {
    self.landscapeOnlyOrientation = YES;
}

- (void)moviePlayerWillExitFullscreenNotification:(NSNotification*)notification {
    self.landscapeOnlyOrientation = NO;
}
Run Code Online (Sandbox Code Playgroud)

然而,一个恼人的问题仍然存在,即如果视频以纵向方向退出全屏(在强制风景中播放之后),则底层视图不会向后旋转.我必须手动将设备旋转到横向并返回到纵向以触发更新方向.有没有什么方法可以以编程方式触发这种更新?

以下一组截图应说明我的意思:

在此输入图像描述 在此输入图像描述 在此输入图像描述

注意:由于各种原因,无法使用MPMoviePlayerViewController.

iphone objective-c mpmovieplayercontroller uiinterfaceorientation ios

14
推荐指数
2
解决办法
1万
查看次数

iOS 8 GM不会更新集合视图的约束

在Xcode 6 Beta 7和之前的所有版本中,我有一个集合视图,当iPad在横向和纵向之间旋转时,它会更新其单元格的约束.现在,它根本没有更新,事实上它看起来就像我将它留在XIB中一样,这对我来说意味着它根本没有更新.我正在使用的可重用视图似乎正在正确更新,但单元格当然不是.

还有其他人遇到过这个问题吗?任何人都有任何关于如何通过它的想法?

我正在使用iOS 7.1模拟器.

cocoa-touch uiinterfaceorientation ios uicollectionview ios8

14
推荐指数
1
解决办法
4713
查看次数