iPhone - 防止图像旋转到其 UIImageView 中

发布于 2024-11-01 09:54:17 字数 1695 浏览 5 评论 0原文

我有一个用于覆盖cameraPicker 的UIView。在这个视图中,我有一个 ImageView,我将相机拍摄的图像(图像属性)放入其中。

当用 iPhone 水平放置照片时,图像会旋转到 ImageView 中。这很糟糕,因为用户看不到拍摄时的照片。

我已将这些代码行放入管理覆盖视图(文件所有者)的 ViewController 中:

- (void)didAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    NSLog(@"didAnimateFirstHalfOfRotationToInterfaceOrientation");
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    NSLog(@"didRotateFromInterfaceOrientation");
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    NSLog(@"shouldAutorotateToInterfaceOrientation");
    return YES;
}

- (void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    NSLog(@"willAnimateFirstHalfOfRotationToInterfaceOrientation");
}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
    NSLog(@"willAnimateRotationToInterfaceOrientation");
}

- (void)willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration
{
    NSLog(@"willAnimateSecondHalfOfRotationFromInterfaceOrientation");
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    NSLog(@"willRotateToInterfaceOrientation");
}

即使我在 shouldAutorotateToInterfaceOrientation 中返回 YES 或 NO,也不会将其他日志项写入控制台。

我真的不介意这一点,但这是一个线索。我最后的愿望是避免图像旋转到其图像视图中。我该怎么做呢?

请考虑您的回答,我们正在讨论相机覆盖层,它的反应方式可能与正常视图不同。

I have an UIView that is used for overlaying a cameraPicker. Into this View, I have an ImageView into which I put the image (image property) taken by the camera.

When the photo is taken with the iPhone in horizontal position, the image is rotated into the ImageView. That's bad because the user don't see the picture as it has been taken.

I had put those lines of code into the ViewController that manages the overlay View (File's owner) :

- (void)didAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    NSLog(@"didAnimateFirstHalfOfRotationToInterfaceOrientation");
}

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    NSLog(@"didRotateFromInterfaceOrientation");
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    NSLog(@"shouldAutorotateToInterfaceOrientation");
    return YES;
}

- (void)willAnimateFirstHalfOfRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    NSLog(@"willAnimateFirstHalfOfRotationToInterfaceOrientation");
}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
{
    NSLog(@"willAnimateRotationToInterfaceOrientation");
}

- (void)willAnimateSecondHalfOfRotationFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration
{
    NSLog(@"willAnimateSecondHalfOfRotationFromInterfaceOrientation");
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    NSLog(@"willRotateToInterfaceOrientation");
}

Even if I return YES or NO into shouldAutorotateToInterfaceOrientation, no other log item is written into the console.

I don't really mind this, but it's a clue. My final wish is to avoid the image to rotate into its image view. How may I do that ?

Please consider into your answer that we are talking about a camera overlay, that could react in a different way than a normal view.

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

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

发布评论

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

评论(1

寂寞清仓 2024-11-08 09:54:17

你的概念是正确的,但方法是错误的。当前设备方向不会影响 UIImage 放置在 UIImageView 内部时的行为方式。如果你想修改这个行为,那么你需要在图像本身上指定一个UIImageOrientation,例如:

UIImage* rotatedImage = [UIImage imageWithCGImage:myImage.CGImage scale:1.0 orientation:UIImageOrientationLeft];
myImageView.image = rotatedImage;

请注意,你可能不想使用UIImageOrientationLeft,那只是为了例子。您需要根据拍摄照片的方向和(可能)当前设备的方向来选择能够为您提供所需最终结果的方向。

You've got the right concept, but the wrong approach. The current device orientation does not affect how a UIImage behaves when placed inside of a UIImageView. If you want to modify this behavior, then you need to specify a UIImageOrientation on the image itself, like:

UIImage* rotatedImage = [UIImage imageWithCGImage:myImage.CGImage scale:1.0 orientation:UIImageOrientationLeft];
myImageView.image = rotatedImage;

Note that you may not want to use UIImageOrientationLeft, that is just for example. You need to pick the orientation that will give you the end result you want based upon the orientation the picture was taken in and (maybe) the current device orientation.

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