iOS实现旋转详解手机开发

#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

原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/5179.html

(0)
上一篇 2021年7月16日
下一篇 2021年7月16日

相关推荐

发表回复

登录后才能评论