iPhone - 防止图像旋转到其 UIImageView 中
我有一个用于覆盖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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的概念是正确的,但方法是错误的。当前设备方向不会影响
UIImage
放置在UIImageView
内部时的行为方式。如果你想修改这个行为,那么你需要在图像本身上指定一个UIImageOrientation
,例如:请注意,你可能不想使用
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 aUIImageView
. If you want to modify this behavior, then you need to specify aUIImageOrientation
on the image itself, like: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.