[英]How to Rotate Image in iPhone?
I am trying to rotate an image in a iPhone application, but I am not able to rotate it for a particular angle which I need. 我正在尝试在iPhone应用程序中旋转图像,但无法将其旋转特定角度。 Can any one help in solving this problem?
有谁能帮助解决这个问题?
#import <UIKit/UIKit.h>
@interface ConsumingWebServicesViewController : UIViewController<UITextFieldDelegate>{
IBOutlet UITextField *username;
IBOutlet UITextField *password;
IBOutlet UITextField *deviceid;
IBOutlet UIActivityIndicatorView *activityindicator;
NSURLConnection *conn;
NSMutableData *webData;
}
@property(nonatomic,retain)UITextField *username;
@property(nonatomic,retain)UITextField *password;
@property(nonatomic,retain)UITextField *deviceid;
@property(nonatomic,retain)UIActivityIndicatorView *activityindicator;
-(IBAction)buttonpressed:(id)sender;
@end
To rotate any UIImageView, if that's what you're asking can be done by applying a CGAffineTransformMakeRotation
to the image's transform property. 要旋转任何UIImageView,如果您要这样做,可以通过将
CGAffineTransformMakeRotation
应用于图像的transform属性来完成。
Example 例
float angleInDegrees = 90; // For example
float angleInRadians = angleInDegrees * (M_PI/180);
myImageView.transform = CGAffineTransformMakeRotation(angleInRadians);
//If someone needs in swift 3 //如果有人需要迅速3
func rotateImageClockWise(theImage: UIImage,imageView:UIImageView) -> UIImage {
var orient: UIImageOrientation!
let imgOrientation = theImage.imageOrientation
UIView.transition(with: imageView, duration: 0.2, options: .transitionCrossDissolve, animations: {() -> Void in
switch imgOrientation {
case .left:
orient = .up
case .right:
orient = .down
case .up:
orient = .right
case .down:
orient = .left
case .upMirrored:
orient = .rightMirrored
case .downMirrored:
orient = .leftMirrored
case .leftMirrored:
orient = .upMirrored
case .rightMirrored:
orient = .downMirrored
}
}, completion: { _ in })
let rotatedImage = UIImage(cgImage: theImage.cgImage!, scale: 1.0, orientation: orient)
return rotatedImage
}
//Just call the method like this : //只需调用如下方法:
rotateImageClockWise(theImage: UIImage,imageView:UIImageView) rotationImageClockWise(theImage:UIImage,imageView:UIImageView)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.