2011-07-27 62 views
-1

我想旋转一个iPhone应用程序中的图像,但我无法旋转它,我需要一个特定的角度。任何人都可以帮助解决这个问题吗?如何在iPhone中旋转图像?

#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 
+0

这段代码没有显示任何东西一个图像。 – jtbandes

+0

[使用一个手指触摸...在中心旋转图像]的可能重复(http://stackoverflow.com/questions/5468559/rotate-image-on-center-using-one-finger-touch) – jtbandes

+0

不是一个清晰的问题 – Hisenberg

回答

3

要旋转任何的UIImageView,如果这就是你在问什么可以通过应用CGAffineTransformMakeRotation到图像的变换属性来完成。

float angleInDegrees = 90; // For example 
float angleInRadians = angleInDegrees * (M_PI/180); 
myImageView.transform = CGAffineTransformMakeRotation(angleInRadians); 
+1

谢谢.....这是工作 – user857280

0

//如果有人在迅速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 
} 

//只需调用这样的方法:

rotateImageClockWise(theImage:UIImage的,ImageView的: UIImageView)