开发者

Gauge animation on iphone

开发者 https://www.devze.com 2023-03-10 14:07 出处:网络
I\'m trying to implement a gauge animation using (+ and - buttons) on iphone, but i have no idea where to start? Any help is really welcome. See the image below (开发者_JAVA百科this is what I\'m tryin

I'm trying to implement a gauge animation using (+ and - buttons) on iphone, but i have no idea where to start? Any help is really welcome. See the image below (开发者_JAVA百科this is what I'm trying to do). Thanks for your help.

Gauge animation on iphone


Here is some open source code (with an example) that implements the gauge view. You of course would still need to do the buttons yourself, and possible add a different visual style.

http://www.cocoacontrols.com/platforms/ios/controls/meterview


You need to rotate the needle based on the angle... Here is the logic You can refer my answer here... Rotating a UIImageView around a point over 10 seconds?

    fireInterval = 10;
//Adjust starting and ending angle
    mStartingAngle = 45; 
    mEndingAngle = 180;
//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;
            }
}

And rotate the needle based on mCurrentAngle....

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号