-1

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. 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
Alex Coplan
  • 13,211
  • 19
  • 77
  • 138
user857280
  • 25
  • 1
  • 5
  • Nothing in this code shows anything about an image. – jtbandes Jul 27 '11 at 07:07
  • possible duplicate of [Rotate image on center using one finger touch...](http://stackoverflow.com/questions/5468559/rotate-image-on-center-using-one-finger-touch) – jtbandes Jul 27 '11 at 07:07

2 Answers2

3

To rotate any UIImageView, if that's what you're asking can be done by applying a CGAffineTransformMakeRotation to the image's transform property.

Example

float angleInDegrees = 90; // For example
float angleInRadians = angleInDegrees * (M_PI/180);
myImageView.transform = CGAffineTransformMakeRotation(angleInRadians);
Alex Coplan
  • 13,211
  • 19
  • 77
  • 138
0

//If someone needs in swift 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)

Swifty Codes
  • 992
  • 10
  • 23