编写简单的视图进入和退出动画
编写了个类似这样的视图动画。
其中灰色部分是子视图(UIView)。点击一下,就上移,再点击就退回。
上来需要添加的是tap手势的处理:
UITapGestureRecognizer *recognizer=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[self addGestureRecognizer:recognizer];
[recognizer release];
在tap时会调用下面的方法:
-(void)handleTap:(UITapGestureRecognizer *)recognizer{
NSLog(@">>>tap it");
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:@"Curl" context:context];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
if (hidden) {
self.frame=CGRectMake(0, 768-100, 1024, 100);
}else {
self.frame=CGRectMake(0, 768-20, 1024, 100);
}
[UIView commitAnimations];
hidden=!hidden;
}
这里hidden是实例变量:
@interface BarView : UIView {
bool hidden;
在上级视图(UIView)中加入了上面的视图:
BarView *barView=[[BarView alloc] initWithFrame:CGRectMake(0, 768-20, 1024, 100)];
[self addSubview:barView];