你好,歡迎來到IOS教程網

 Ios教程網 >> IOS使用技巧 >> IOS技巧綜合 >> iOS 實現轉盤的效果

iOS 實現轉盤的效果

編輯:IOS技巧綜合
[摘要]本文是對iOS 實現轉盤的效果的講解,對學習IOS蘋果軟件開發有所幫助,與大家分享。

效果

#import "ViewController.h"


@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *panImageView;
/**  */
@property(nonatomic,assign)int angle;
/** 轉盤時間 */
@property(strong,nonatomic)NSTimer *timer;
/** 計時器 */
@property(strong,nonatomic)NSTimer *timeTick;
/** 計時時間 */
@property(nonatomic,assign)int timeNumber;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.timeNumber = 3;
   self.timer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(startAnimation) userInfo:nil repeats:YES];
    self.timeTick = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES];
    
}
-(void)startAnimation
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [UIView setAnimationDelegate:self];
    _panImageView.animationRepeatCount = 1;
//    [UIView setAnimationDidStopSelector:@selector(startAnimation)];
    self.angle += 1000;
    self.panImageView.layer.anchorPoint = CGPointMake(0.5,0.5);//以右下角為原點轉,(0,0)是左上角轉,(0.5,0,5)心中間轉,其它以此類推
    self.panImageView.transform = CGAffineTransformMakeRotation(self.angle * (M_PI / 180.0f));
    
    [UIView commitAnimations];
    
}

-(void)timeFireMethod{
    self.timeNumber -- ;
    if (self.timeNumber == 0) {
        [self.timer invalidate];
    }


}
@end
  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved