【问题标题】:iPhone view shows wrong orientationiPhone 视图显示方向错误
【发布时间】:2011-03-21 01:18:06
【问题描述】:

我正在努力解决这个问题。 我的应用需要纵向视图和横向视图。现在,当我创建 2 个显示纵向视图和横向视图(由 shouldAutorotateToInterfaceOrientation 强制)的按钮时,它们显示得很好。但是当我从图像选择器的结果代码中调用视图时,纵向视图工作得很好,但是横向视图会像这样返回。 http://bit.ly/bfbobc.

所以要说清楚:nob 已经转了 90 度,imageviewcontrol 只显示了一半(右侧部分在屏幕外)...但是 iPhone 没有被强制进入横向模式...

有人可以解释一下这里发生了什么或我如何实现这一点!欢迎任何帮助!

这就是我使用 imagepickercontroller 结果代码调用视图的方式。

`- (void) imagePickerController:(UIImagePickerController *)vcImagePicker didFinishPickingMediaWithInfo:(NSDictionary *)info { NSLog(@"图片已被拍摄/选择,现在我们需要决定展示哪个视图");

[vcImagePicker dismissModalViewControllerAnimated:YES];

UIImage *chosenPicture = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

if (chosenPicture.size.width > chosenPicture.size.height) {
    NSLog(@"pic is in landscape");

    EditLandscapeScreen *vcEditLandscapeScreen = [[EditLandscapeScreen alloc] initWithNibName:@"EditLandscapeScreen" bundle:nil];
    vcEditLandscapeScreen.ChosenImage = chosenPicture;
    [self.view addSubview:vcEditLandscapeScreen.view]; 
    [vcEditLandscapeScreen release];
}
else {
    NSLog(@"pic is in portrait");

    EditPortraitScreen *vcEditPortraitScreen = [[EditPortraitScreen alloc] initWithNibName:@"EditPortraitScreen" bundle:nil];
    vcEditPortraitScreen.ChosenImage = chosenPicture;
    [self.view addSubview:vcEditPortraitScreen.view]; 
    [vcEditPortraitScreen release];
}

}`

【问题讨论】:

    标签: iphone xcode view uiimageview rotation


    【解决方案1】:

    如果您将子视图添加到视图,您必须自己更改子视图的方向。 willRotateToInterfaceOrientation 只会为第一个视图控制器调用,因此如果您将子视图添加到视图控制器,这可能是您可以接受的方式:

    在您的视图控制器中:

    - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
        for (int i = 0; i < [self.viewControllers count]; i++ ) {
            [[self.viewControllers objectAtIndex:i] didRotateFromInterfaceOrientation:fromInterfaceOrientation];
        }
    }
    

    在你的 Subview ViewController 中:

    - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
        [self adjustViewsForOrientation:self.interfaceOrientation];
    }
    
        - (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation {
            if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
                NSLog(@"Subview Landscape");
                //Do Your Landscape Changes here
            }
            else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
                NSLog(@"Subview Portrait");
                //Do Your Portrait Changes here
            }
        }
    

    这可能会让你朝着正确的方向前进。

    【讨论】:

    • 我知道你要去哪里,但我想在子视图上强制横向,而不仅仅是提供横向的可能性。我使用“shouldAutorotateToInterfaceOrientation”强制执行此操作并为左右横向模式返回“是”,但是当我调用子视图时,这种“强制”操作不起作用......对此有什么想法吗?还是谢谢!
    猜你喜欢
    • 2020-03-10
    • 2019-11-27
    • 1970-01-01
    • 1970-01-01
    • 2012-11-26
    • 2014-02-22
    • 1970-01-01
    • 1970-01-01
    • 2011-05-27
    相关资源
    最近更新 更多