iPhone控件之UIView

本文详细介绍了如何使用Objective-C编程语言创建复杂的视图动画效果,包括子视图的大小变化、位置调整以及颜色变化等。通过实例演示了如何设置视图的属性、使用UIView类的方法实现动画,并在代码中加入关键的自定义动画逻辑。

- (void)viewDidLoad {

[super viewDidLoad];

CGPoint frameCenter = self.view.center;
float width = 50.0;
float height = 50.0;

CGRect viewFrame = CGRectMake(frameCenter.x-width,frameCenter.y-height, width*2, height*2);
UIView *myView = [[UIView alloc] initWithFrame:viewFrame];
myView.backgroundColor = [UIColor blueColor];

//create subview
CGRect subViewFrame = CGRectInset(myView.bounds, width/2.0, height/2.0);
UIView *mySubview = [[UIView alloc] initWithFrame:subViewFrame];
mySubview.backgroundColor = [UIColor yellowColor];

//set autoresizing mask
mySubview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

[myView addSubview:mySubview];

[[self view] addSubview:myView];

//animate resize
[UIView beginAnimations:nil context:NULL];

[UIView setAnimationDuration:1.0];
viewFrame = CGRectInset(viewFrame, -width, -height);
[myView setFrame:viewFrame];

[UIView commitAnimations];

[mySubview release];
[myView release];
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值