定制UIImagePickController遇到的设备和照片方向问题

背景:定制了UIImagePickController的view,用横版的UI,引导用户去做横屏拍摄,

需求: 让用户在确认照片时,照片始终横版向右

设备的方向:

typedef enum {
   UIDeviceOrientationUnknown,
   UIDeviceOrientationPortrait,
   UIDeviceOrientationPortraitUpsideDown,
   UIDeviceOrientationLandscapeLeft,
   UIDeviceOrientationLandscapeRight,
   UIDeviceOrientationFaceUp,
   UIDeviceOrientationFaceDown
} UIDeviceOrientation;
图片的方向

typedef NS_ENUM(NSInteger, UIImageOrientation) {

    UIImageOrientationUp,            // default orientation

    UIImageOrientationDown,          // 180 deg rotation

    UIImageOrientationLeft,          // 90 deg CCW

    UIImageOrientationRight,         // 90 deg CW

    UIImageOrientationUpMirrored,    // as above but image mirrored along other axis. horizontal flip

    UIImageOrientationDownMirrored,  // horizontal flip

    UIImageOrientationLeftMirrored,  // vertical flip

    UIImageOrientationRightMirrored, // vertical flip

};


要点1:用户横版拍摄时,设备方向可能是任意方向,而不是预期的横版,设备的方向来源自上次重力感应的结果,横着手机平移是不会改变设备方向的,
要点2;用四个方向,描述3D世界手机位置,会失去一部分信息,所以默认状态时手机屏幕始终朝向使用者
方法1:旋转图像,来完成像素的改变

transform = CGAffineTransformTranslate(transform, self.size.width, 0);
transform = CGAffineTransformRotate(transform, M_PI_2);
工程源代码
https://gist.github.com/alex-cellcity/1531596

方法2:改变图片方向,来改变显示

    CGImageRef ciimage = self.CGImage;

    UIImage *image = [[UIImage alloc] initWithCGImage:ciimage scale:1.0 orientation:UIImageOrientationUp];

UIImage方向问题

http://www.cnblogs.com/smileEvday/archive/2013/05/14/UIImage.html




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值