IT虾米网

iOS实现旋转详解

developer 2018年06月24日 手机开发 322 0
#import "ViewController.h" 
  
@interface ViewController () 
@property (strong, nonatomic)UILabel *label; 
@end 
  
@implementation ViewController 
  
- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    CGRect labelFrame = CGRectMake(100, 100,100, 50); 
    self.label = [[UILabel alloc] initWithFrame:labelFrame]; 
    self.label.font = [UIFont fontWithName:@"Helvetica" size:36]; 
    self.label.text = @"XxxX"; 
    self.label.textAlignment = NSTextAlignmentCenter; 
    self.label.backgroundColor = [UIColor brownColor]; 
    [self.view addSubview:self.label]; 
    [self rotateLabelDown]; 
} 
  
- (void)rotateLabelDown{ 
    [UIView animateWithDuration:10 animations:^{ 
        self.label.layer.anchorPoint = CGPointMake(0.5, 0.5); 
        //self.label.transform = CGAffineTransformMakeRotation(-90);  //逆时针旋转 
        self.label.transform = CGAffineTransformMakeRotation(M_PI); 
    } completion:^(BOOL finished) { 
        [self rotateLabelUp]; 
    }]; 
} 
  
- (void)rotateLabelUp{ 
    [UIView animateWithDuration:10 animations:^{ 
        self.label.layer.anchorPoint = CGPointMake(0.5, 0.5); 
        self.label.transform = CGAffineTransformMakeRotation(0); 
    } completion:^(BOOL finished) { 
        [self rotateLabelDown]; 
    }]; 
} 
  
- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 
  
@end

发布评论

分享到:

IT虾米网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!

iOS通过Http 上传图片详解
你是第一个吃螃蟹的人
发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。