iOS實現旋轉

b36g 9年前發布 | 1K 次閱讀 Objective-C 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</pre>

 本文由用戶 b36g 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!