iPhone 视图显示方向错误

发布于 2024-09-11 09:35:31 字数 1480 浏览 3 评论 0原文

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

所以只要说清楚:旋钮已经旋转了 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];
}

}`

I'm wrestling with this problem.
I need a portrait view and a landscape view for my App. Now when I create 2 buttons that show me a portrait view and a landscape view (forced by shouldAutorotateToInterfaceOrientation) they show up just fine. But when I call the views from within the result code of an imagepicker, the portraitview works just fine, but the landscape view get returned like this. http://bit.ly/bfbobc.

So just the make it clear: the nob is already turned 90 degrees, the imageviewcontrol is only shown half (the right part is off-screen)... But the iPhone isn't forced into landscape mode...

Can someone please explain me what's going on here or how I can achieve this! Any help is welcome!

This is how I call the views from withing the imagepickercontroller result code.

`- (void) imagePickerController:(UIImagePickerController *)vcImagePicker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSLog(@"The picture was taken/chosen, now we need to decide which view to present");

[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];
}

}`

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

阳光下的泡沫是彩色的 2024-09-18 09:35:31

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

在您的 ViewController 中:

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

在您的子视图 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
        }
    }

这可能您会朝正确的方向前进。

If you add a Subview to a View you have to make the Orientation changes for your Subview yourself. willRotateToInterfaceOrientation only will get called for the first viewcontroller so if you add Subviews to a viewcontroller this may be a acceptable way for you:

in your ViewController:

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

in you 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
        }
    }

This may you get in the right direction.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文