2011-07-27 86 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)