#import "RootViewController.h"
@interface RootViewController () {
UIView *oneView;
UIView *middleView;
UIView *bigView;
}
@end
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor blackColor];
bigView = [[UIView alloc] initWithFrame:CGRectMake(20, 160, 335, 335)];
// bigView.backgroundColor = [UIColor orangeColor];
bigView.layer.borderWidth = 1;
bigView.layer.borderColor = [UIColor colorWithWhite:1.000 alpha:0.200].CGColor;
bigView.layer.cornerRadius = 167.5;
[self.view addSubview:bigView];
[bigView release];
[NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(taiji2) userInfo:nil repeats:YES];
UIView *bigView1 = [[UIView alloc] initWithFrame:CGRectMake(317.5, 150, 35, 35)];
bigView1.backgroundColor = [UIColor colorWithRed:0.844 green:0.872 blue:0.610 alpha:1.000];
bigView1.layer.cornerRadius = 17.5;
[bigView addSubview:bigView1];
[bigView1 release];
middleView = [[UIView alloc] initWithFrame:CGRectMake(42.5, 42.5, 250, 250)];
// middleView.backgroundColor = [UIColor yellowColor];
middleView.layer.borderWidth = 1;
middleView.layer.borderColor = [UIColor colorWithWhite:1.000 alpha:0.200].CGColor;
middleView.layer.cornerRadius = 125.5;
[bigView addSubview:middleView];
[middleView release];
[NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(taiji1) userInfo:nil repeats:YES];
UIView *middleView1 = [[UIView alloc] initWithFrame:CGRectMake(232.5, 107.5, 35, 35)];
middleView1.backgroundColor = [UIColor colorWithRed:0.689 green:0.624 blue:0.632 alpha:1.000];
middleView1.layer.cornerRadius = 17.5;
[middleView addSubview:middleView1];
[middleView1 release];
oneView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 150, 150)];
// oneView.backgroundColor = [UIColor cyanColor];
oneView.layer.borderWidth = 1;
oneView.layer.borderColor = [UIColor colorWithWhite:1.000 alpha:0.200].CGColor;
oneView.layer.cornerRadius = 75;
[middleView addSubview:oneView];
[oneView release];
[NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(taiji) userInfo:nil repeats:YES];
UIView *smillView = [[UIView alloc] initWithFrame:CGRectMake(130, 55, 40, 40)];
smillView.backgroundColor = [UIColor colorWithRed:0.758 green:0.714 blue:0.535 alpha:1.000];
smillView.layer.cornerRadius = 20;
[oneView addSubview:smillView];
[smillView release];
UIView *centreView = [[UIView alloc] initWithFrame:CGRectMake(45, 45, 60, 60)];
centreView.backgroundColor = [UIColor colorWithRed:0.600 green:0.400 blue:0.200 alpha:0.220];
centreView.layer.cornerRadius = 30;
[oneView addSubview:centreView];
[centreView release];
}
//oneView转
- (void)taiji {
[UIView animateWithDuration:3 delay:0 options:(UIViewAnimationOptionCurveLinear) animations:^{
oneView.transform = CGAffineTransformRotate(oneView.transform, M_PI_4);
} completion:^(BOOL finished) {
}];
}
//middleView转
- (void)taiji1 {
[UIView animateWithDuration:3 delay:0 options:(UIViewAnimationOptionCurveLinear) animations:^{
middleView.transform = CGAffineTransformRotate(oneView.transform, M_PI_4);
} completion:^(BOOL finished) {
}];
}
//middleView转
- (void)taiji2 {
[UIView animateWithDuration:3 delay:0 options:(UIViewAnimationOptionCurveLinear) animations:^{
bigView.transform = CGAffineTransformRotate(oneView.transform, M_PI_4);
} completion:^(BOOL finished) {
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
@interface RootViewController () {
UIView *oneView;
UIView *middleView;
UIView *bigView;
}
@end
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor blackColor];
bigView = [[UIView alloc] initWithFrame:CGRectMake(20, 160, 335, 335)];
// bigView.backgroundColor = [UIColor orangeColor];
bigView.layer.borderWidth = 1;
bigView.layer.borderColor = [UIColor colorWithWhite:1.000 alpha:0.200].CGColor;
bigView.layer.cornerRadius = 167.5;
[self.view addSubview:bigView];
[bigView release];
[NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(taiji2) userInfo:nil repeats:YES];
UIView *bigView1 = [[UIView alloc] initWithFrame:CGRectMake(317.5, 150, 35, 35)];
bigView1.backgroundColor = [UIColor colorWithRed:0.844 green:0.872 blue:0.610 alpha:1.000];
bigView1.layer.cornerRadius = 17.5;
[bigView addSubview:bigView1];
[bigView1 release];
middleView = [[UIView alloc] initWithFrame:CGRectMake(42.5, 42.5, 250, 250)];
// middleView.backgroundColor = [UIColor yellowColor];
middleView.layer.borderWidth = 1;
middleView.layer.borderColor = [UIColor colorWithWhite:1.000 alpha:0.200].CGColor;
middleView.layer.cornerRadius = 125.5;
[bigView addSubview:middleView];
[middleView release];
[NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(taiji1) userInfo:nil repeats:YES];
UIView *middleView1 = [[UIView alloc] initWithFrame:CGRectMake(232.5, 107.5, 35, 35)];
middleView1.backgroundColor = [UIColor colorWithRed:0.689 green:0.624 blue:0.632 alpha:1.000];
middleView1.layer.cornerRadius = 17.5;
[middleView addSubview:middleView1];
[middleView1 release];
oneView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 150, 150)];
// oneView.backgroundColor = [UIColor cyanColor];
oneView.layer.borderWidth = 1;
oneView.layer.borderColor = [UIColor colorWithWhite:1.000 alpha:0.200].CGColor;
oneView.layer.cornerRadius = 75;
[middleView addSubview:oneView];
[oneView release];
[NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(taiji) userInfo:nil repeats:YES];
UIView *smillView = [[UIView alloc] initWithFrame:CGRectMake(130, 55, 40, 40)];
smillView.backgroundColor = [UIColor colorWithRed:0.758 green:0.714 blue:0.535 alpha:1.000];
smillView.layer.cornerRadius = 20;
[oneView addSubview:smillView];
[smillView release];
UIView *centreView = [[UIView alloc] initWithFrame:CGRectMake(45, 45, 60, 60)];
centreView.backgroundColor = [UIColor colorWithRed:0.600 green:0.400 blue:0.200 alpha:0.220];
centreView.layer.cornerRadius = 30;
[oneView addSubview:centreView];
[centreView release];
}
//oneView转
- (void)taiji {
[UIView animateWithDuration:3 delay:0 options:(UIViewAnimationOptionCurveLinear) animations:^{
oneView.transform = CGAffineTransformRotate(oneView.transform, M_PI_4);
} completion:^(BOOL finished) {
}];
}
//middleView转
- (void)taiji1 {
[UIView animateWithDuration:3 delay:0 options:(UIViewAnimationOptionCurveLinear) animations:^{
middleView.transform = CGAffineTransformRotate(oneView.transform, M_PI_4);
} completion:^(BOOL finished) {
}];
}
//middleView转
- (void)taiji2 {
[UIView animateWithDuration:3 delay:0 options:(UIViewAnimationOptionCurveLinear) animations:^{
bigView.transform = CGAffineTransformRotate(oneView.transform, M_PI_4);
} completion:^(BOOL finished) {
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
本文介绍了一个使用Objective-C创建太极图案动画的过程。通过设置不同大小的视图并运用UIView动画进行旋转,实现了太极图案的动态效果。文章详细展示了如何定义视图、设置属性以及定时触发动画。

6031

被折叠的 条评论
为什么被折叠?



