user440096
user440096

Reputation:

Rotating a UIImageView around a point over 10 seconds?

I have a UIImageView setup called needleImageView which i need to rotate 360degrees over 10 seconds the point 20.00 20.00 of the ImageView.

Anybody able to show me sample code for this functionality?

Thanks, -Code

Upvotes: 0

Views: 331

Answers (1)

Chandan Shetty SP
Chandan Shetty SP

Reputation: 5117

Here is the logic... Try implementing.

On starting timer

//in header file

fireInterval = 10;
mStartingAngle = 0;
mEndingAngle = 360;

//Implementation

-(void) startTimer
{
 mPreviousTime = [NSDate timeIntervalSinceReferenceDate];
}

In the loop

-(void) updateFunction
{
    NSTimeInterval timeNow = [NSDate timeIntervalSinceReferenceDate];

            //NewValue = (((OldValue - OldMin) * (NewMax - NewMin)) / (OldMax - OldMin)) + NewMin
            //Mapping values between mStartAngle and mEndAngle
            mCurrentAngle = (((timeNow - mPreviousTime) * (mEndingAngle - mStartingAngle)) / (previousTime+fireInterval - mPreviousTime)) + mStartingAngle;

            if( mPreviousTime + fireInterval <= timeNow )
            {
                NSLog(@"10 seconds completed");
                mPreviousTime = timeNow;
            }
}

Upvotes: 4

Related Questions