Fork me on GitHub

编写简单的视图进入和退出动画

编写了个类似这样的视图动画。

imageimage

其中灰色部分是子视图(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];

posted on 2012-02-10 09:02  pengyingh  阅读(216)  评论(0)    收藏  举报

导航