抽屉效果的实现原理
2015-08-11 15:39
429 查看
@property (nonatomic, strong)UIImageView *choytiimage; @property (nonatomic, strong)UIButton *choutibutton; @property (nonatomic, strong)UIButton *button; @property (nonatomic, strong)UILabel *label; @property (nonatomic, strong)UILabel *label1; @property (nonatomic, strong)UILabel *label2; @property (nonatomic, strong)UIView *aview; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //利用layer层来隐藏 刚开始View是隐藏的 在BUtton点击方法里它会发挥用处 _aview = [[UIView alloc]init]; _aview.frame = CGRectMake(-200, 0,200, 667); _aview.backgroundColor = [UIColor orangeColor]; [self.view addSubview:_aview]; //label也处于隐藏 _label = [[UILabel alloc]initWithFrame:CGRectMake(-200, 200, 60, 30)]; _label.text = @"图片"; _label.textAlignment = NSTextAlignmentCenter; _label.textColor = [UIColor blueColor]; [self.view addSubview:_label]; _label1 = [[UILabel alloc]initWithFrame:CGRectMake(-200, 240, 60, 30)]; _label1.text = @"作品"; _label1.textColor = [UIColor redColor]; _label1.textAlignment = NSTextAlignmentCenter; [self.view addSubview:_label1]; _label2 = [[UILabel alloc]initWithFrame:CGRectMake(-200, 280, 60, 30)]; _label2.text = @"展示"; _label2.textAlignment = NSTextAlignmentCenter; _label2.textColor = [UIColor purpleColor]; [self.view addSubview:_label2]; _choytiimage = [[UIImageView alloc]init]; _choytiimage.frame = CGRectMake(0, 0, 375, 667); _choytiimage.image = [UIImage imageNamed:@"433.jpg"]; [self.view addSubview:_choytiimage]; _choutibutton = [UIButton buttonWithType:UIButtonTypeCustom]; [_choutibutton setTitle:@"抽屉" forState:UIControlStateNormal]; _choutibutton.frame = CGRectMake(10, 50, 60, 30); [_choutibutton setTitleShadowColor:[UIColor orangeColor] forState:UIControlStateNormal]; [_choutibutton addTarget:self action:@selector(choyti:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:_choutibutton]; _button = [UIButton buttonWithType:UIButtonTypeCustom]; [_button setTitle:@"返回" forState:UIControlStateNormal]; _button.frame = CGRectMake(300, 50, 60, 30); [_button setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal]; [_button addTarget:self action:@selector(rtr:) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:_button]; } -(void)choyti:(UIButton *)sender { //抽屉效果主要的就是 在于UIView的动画效果 View从-200 通过动画效果展示出来 [UIView animateWithDuration:1.5f animations:^{ _choytiimage.frame = CGRectMake(200, 0, 200, 667); }]; [UIView animateWithDuration:2.0f animations:^{ _label.frame = CGRectMake(22, 200, 60, 30); }]; [UIView animateWithDuration:2.2f animations:^{ _label1.frame = CGRectMake(22, 240, 60, 30); }]; [UIView animateWithDuration:2.4f animations:^{ _label2.frame = CGRectMake(22, 280, 60, 30); }]; [UIView animateWithDuration:1.5f animations:^{ _aview.frame = CGRectMake(0, 0, 200, 667); }]; } -(void)rtr:(UIButton *)sender { [UIView animateWithDuration:2.0f animations:^{ //点击返回按钮 恢复原来image _choytiimage.frame = CGRectMake(0, 0, 375, 667); }]; }
相关文章推荐
- 美团Android自动化之旅—适配渠道包
- 缺失文件错误-Prefix.pch
- POJ 1664 放苹果
- Struts2下载文件点取消、重复下载出现的异常解决
- 软工视频——第三章
- CentOS Linux下Java环境的安装和配置 (CentOS+JDK1.6.0_11)
- Android Studio Drawable和Mipmap文件夹的区别
- Redis监控方案
- 火星上发生的事情与Vxworks操作系统的优先级反转问题
- 美团Android自动化之旅—适配渠道包
- 美团Android自动化之旅—适配渠道包
- Windows下配置PHP支持LDAP扩展方法(wampserver)
- uploadify3.2.1+struts2实现多文件上传
- 史上最详细的Android Studio系列教程四--Gradle基础
- debian8 安装 mysql5.6和简单配置
- pc/app 项目/功能设计
- python不同package下相互调用
- iOS-开发技巧-UILabel内容模糊的原因
- Django Models的数据类型 汇总
- POJ 2195 && HDU 1533 Going Home(最小费用最大流-mcmf)