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.
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.
精彩评论