iOS开发——view内缩弹窗
来源:互联网 发布:京东关键词优化 编辑:程序博客网 时间:2024/05/21 17:19
1. 实现的效果图如下:
2.实现原理:
控制器的self.view背景色为黑色
需要一个是底部白色的背景view:backgroundView
再一个底部弹出的view: topview
3.代码如下:
.h
//// ViewInsidePopController.h// A-C//// Created by 刘成利 on 2017/4/06.// Copyright © 2017年 刘成利. All rights reserved.//#import "NormalTitleViewController.h"@interface ViewInsidePopController : NormalTitleViewController@end
.m
部分view是控制器父类创建好的
//// ViewInsidePopController.m// A-C//// Created by 刘成利 on 2017/4/06.// Copyright © 2017年 刘成利. All rights reserved.//#import "ViewInsidePopController.h"@interface ViewInsidePopController ()@property (nonatomic, strong) UIView *buttomView; // 底部白色view@property (nonatomic, strong) UIView *topView; // 弹出的view@property (nonatomic, assign) BOOL isShowTopView; // 标记是否弹出@end@implementation ViewInsidePopController- (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor blackColor]; self.titleView.backgroundColor = [[UIColor lightGrayColor] colorWithAlphaComponent:0.3]; //导航栏背景色 self.buttomView = [[UIView alloc]initWithFrame:self.view.bounds]; self.buttomView.backgroundColor = [UIColor cyanColor]; [self.backgroundView addSubview:self.buttomView]; // 半黑透明 UIView * maskView = [[UIView alloc]initWithFrame:self.view.bounds]; maskView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5]; maskView.alpha = 0; maskView.tag = 1000; [self.buttomView addSubview:maskView]; // 初始化 弹出窗口 self.topView = [[UIView alloc]initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height /2.0)]; self.topView.backgroundColor = [UIColor whiteColor]; //加个阴影 self.topView.layer.shadowColor = [UIColor blackColor].CGColor; self.topView.layer.shadowOffset = CGSizeMake(0.5, 0.5); self.topView.layer.shadowOpacity = 0.8; self.topView.layer.shadowRadius = 5; //关闭btn UIButton * closeBtn = [UIButton buttonWithType:UIButtonTypeCustom]; closeBtn.frame = CGRectMake(15, 0, 50, 40); [closeBtn setTitle:@"关闭" forState:UIControlStateNormal]; [closeBtn setTitleColor:[UIColor colorWithRed:217/255.0 green:110/255.0 blue:90/255.0 alpha:1] forState:UIControlStateNormal]; [closeBtn addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside]; [self.topView addSubview:closeBtn]; }// 展现- (void)show{ self.isShowTopView = YES; self.titleView.hidden = YES; UIWindow *window = [UIApplication sharedApplication].keyWindow; [window addSubview:self.topView]; CGRect frame = self.topView.frame; frame.origin.y = self.view.frame.size.height/2.0; [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ [self.backgroundView.layer setTransform:[self firstTransform]]; } completion:^(BOOL finished) { [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ [self.backgroundView.layer setTransform:[self secondTransform]]; //显示maskView UIView *maskView = [self.view viewWithTag:1000]; [maskView setAlpha:0.5f]; //popView上升 self.topView.frame = frame; } completion:^(BOOL finished) { }]; }];}- (CATransform3D)firstTransform{ CATransform3D t1 = CATransform3DIdentity; t1.m34 = 1.0/-900; //带点缩小的效果 t1 = CATransform3DScale(t1, 0.95, 0.95, 1); //绕x轴旋转 t1 = CATransform3DRotate(t1, 15.0 * M_PI/180.0, 1, 0, 0); return t1; }- (CATransform3D)secondTransform{ CATransform3D t2 = CATransform3DIdentity; t2.m34 = [self firstTransform].m34; //向上移 t2 = CATransform3DTranslate(t2, 0, self.view.frame.size.height * (-0.08), 0); //第二次缩小 t2 = CATransform3DScale(t2, 0.8, 0.8, 1); return t2;}// 关闭- (void)close{ CGRect frame = self.topView.frame; frame.origin.y += self.view.frame.size.height/2.0; [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ //maskView隐藏 UIView *maskView = [self.view viewWithTag:1000]; [maskView setAlpha:0.0f]; //popView下降 self.topView.frame = frame; } completion:^(BOOL finished) { [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ //变为初始值 [self.backgroundView.layer setTransform:CATransform3DIdentity]; } completion:^(BOOL finished) { //移除 [self.topView removeFromSuperview]; self.isShowTopView = NO; self.titleView.hidden = NO; }]; }]; [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{ //和上个动画同时进行 感觉更丝滑 [self.backgroundView.layer setTransform:[self firstTransform]]; } completion:^(BOOL finished) { }]; }- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { if (self.isShowTopView == NO) { [self show]; } }@end
1 0
- iOS开发——view内缩弹窗
- iOS开发之自定义view—Quartz2D
- IOS开发之——自定义的Activity Indicator View
- IOS开发之——自定义的Activity Indicator View
- iOS开发UI篇—控制器的View的创建
- iOS开发UI篇—控制器的View的创建
- IOS开发—通过ChildViewController实现view的切换
- iOS开发UI篇—控制器的View的创建
- iOS开发UI篇—控制器的View的创建
- iOS开发UI篇—控制器的View的创建
- iOS项目开发实战(Swift)—View之间传递数据
- IOS开发—通过ChildViewController实现view的切换
- iOS开发UI篇—控制器的View的创建
- iOS项目开发实战(Swift)—View之间传递数据
- IOS开发——旋转(CGAffineTransformMakeRotation)之后view和子view坐标系的变化
- iOS—Model,Controller,View
- iOS开发之自定义View
- iOS开发之自定义View
- vector 中 erase 用法注意事项
- 2017浙江省选二试第二天游记
- Android长连接之mina
- 正则表达式
- linux下常用的命令
- iOS开发——view内缩弹窗
- Java中的集合特点总结
- 1130. Infix Expression (25)
- Http学习
- FFmpeg_3.2.4+SDL_2.0.5学习(1)音视频解码帧及显示/播放数据
- java并发编程之——volatile详解
- python如何实现简单的爬虫功能
- Java报表工具打印方案对比
- EA&UML日拱一卒--类图::协作(collaboration)