码迷,mamicode.com
首页 > 移动开发 > 详细

iOS实现旋转

时间:2015-04-03 15:44:37      阅读:148      评论:0      收藏: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



iOS实现旋转

标签:

原文地址:http://my.oschina.net/u/1782374/blog/395679

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!