我有一个简单代码的问题。无论是从相册选择还是使用相机拍摄的照片都会被旋转。起初我以为是UIView中的设置问题,但当我使用CGImageRef将传入的UIImage复制到另一个UIImage时,它仍然发生了旋转。我这样做是因为这是确保我使用副本最简单的方式。如果我搞错了,请纠正这段代码。
代码如下:
- (id)initWithImage:(UIImage *)image {
if ((self = [super init]) && (image != nil)) {
CGImageRef tmpImageRef = [image CGImage];
puzzle = [[UIImage alloc] initWithCGImage:tmpImageRef];
}
return self;
}
调试器:
This GDB was configured as "--host=i386-apple-darwin --target=arm-apple-darwin".tty /dev/ttys001
Loading program into debugger…
sharedlibrary apply-load-rules all
Program loaded.
target remote-mobile /tmp/.XcodeGDBRemote-25694-49
Switching to remote-macosx protocol
mem 0x1000 0x3fffffff cache
mem 0x40000000 0xffffffff none
mem 0x00000000 0x0fff none
run
Running…
[Switching to thread 11523]
[Switching to thread 11523]
Re-enabling shared library breakpoint 1
Re-enabling shared library breakpoint 2
continue
2010-07-13 15:09:17.159 Golovomka[693:307] Using two-stage rotation animation. To use the smoother single-stage animation, this application must remove two-stage method implementations.
2010-07-13 15:09:17.172 Golovomka[693:307] Using two-stage rotation animation is not supported when rotating more than one view controller or view controllers not the window delegate
Current language: auto; currently objective-c
(gdb) print (CGSize)[image size]
$1 = {
width = 1536,
height = 2048
}
(gdb) n
28 puzzle = [[UIImage alloc] initWithCGImage:tmpImageRef];
(gdb)
31 return self;
(gdb) print (CGSize)[puzzle size]
$2 = {
width = 2048,
height = 1536
}
(gdb)
第一次打印出现在CGImageRef实例化行。非常感谢你的帮助。正如我所说,这种情况不会在模拟器中发生,只有当我将代码部署到真实设备时才会发生。
请注意,这篇文章曾经说过这个问题只会在设备上调试时出现,而不会在模拟器中出现。但是我已经将我的iphone 3gs相机拍摄的照片复制到了模拟器中,完全相同的问题也发生了。因此,如果你手头有一张2048x1536的图片,你应该能够在模拟器中复制这个问题。