Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to rotate a UIImageView

Hello,

I need help to implement a function in my code xcode to rotate a single image on its own axis. The image needs to rotate to click a button and then must stop when this button is pushed again. I managed to make a schedule to do this by looking at some tutorials, but not working correctly, by clicking on the image rotacionamento this, but this also moving laterally, not just this rotating in own central axis, the image needs to be stopped and only turn. I'm using the code below to do this function. Can someone help me tweak this code or suggest any other better solution? Thank you for your help. Below the code I'm using.



In ViewController.m

/

// ViewController.m

// Motrista da rodada

//

// Created by Alexsandre Andrade on 23/03/13.

// Copyright (c) 2013 Alexsandre Andrade. All rights reserved.

//


#import "ViewController.h"


@interfaceViewController ()


@end


@implementation ViewController


@synthesize theButton, theImageView;


-(void)rotateRoulette

{

theImageViewLogo.hidden=YES;

theImageView.hidden=NO;

theButton.titleLabel.text = @"Parar";

self.theImageView.center=CGPointMake(self.theImageView.center.x, self.theImageView.center.y);

self.theImageView.transform=CGAffineTransformMakeRotation (angle);

angle+=0.4;

}



-(IBAction)runRoulette:(id)sender

{

if(!runStop)

{

theTimer = [NSTimerscheduledTimerWithTimeInterval:1.0/40.0target:selfselector:@selector(rotateRoulette) userInfo:nilrepeats:YES];

}

else

{

[theTimer invalidate];

theTimer = nil;

}

runStop = !runStop;

}


- (void)viewDidLoad

{

[superviewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

angle = 0;

runStop = FALSE;

}


- (void)didReceiveMemoryWarning

{

[superdidReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}


@end


-------------------------------------------------------------------------------- ---------


In ViewController.h


/

// ViewController.h

// Motrista da rodada

//

// Created by Alexsandre Andrade on 23/03/13.

// Copyright (c) 2013 Alexsandre Andrade. All rights reserved.

//


//#import <UIKit/UIKit.h>


//@interface ViewController : UIViewController

//@property (weak, nonatomic) IBOutlet UIImageView *seta;

//@property (weak, nonatomic) IBOutlet UIImageView *image;


#import <UIKit/UIKit.h>


@interface ViewController : UIViewController

{

IBOutlet UIImageView *theImageViewLogo;

IBOutlet UIImageView *theImageView;

IBOutlet UIButton *theButton;

NSTimer *theTimer;

float angle;

BOOL runStop;

}


@property (atomic, retain) IBOutletUIImageView *theImageView;

@property (atomic, retain) IBOutletUIButton *theButton;


-(IBAction)runRoulette:(id)sender;




@end


-------------------------------------------------------------------------------- --------------






thanks!!

iPhone 4, iOS 6.1

Posted on Mar 25, 2013 7:55 PM

Reply
Question marked as Best reply

Posted on Mar 26, 2013 4:20 AM

If you have Autolayout turned on for your XIB/storyboard, try turning it off.

6 replies

How to rotate a UIImageView

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.