小区宝首页导航栏左边有一个物业按钮,点击时会出现一个视图动画,之前用的是一个POP第三方,想着几个POP动画就要引用一堆的第三方有点麻烦,就试着自己写了一下,功能实现了,下一步就是优化将其封装一下。下面我用DatePicker做的主要是想着再做出点击弹出按钮在底部出现DatePicker选择器。

#import "ViewController.h"
#import "PageViewController.h"
#import "myView.h"

@interface ViewController ()
@property(nonatomic,strong) myView *myview;
@property(nonatomic,strong) UIDatePicker *dataPicker;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"预览" style:UIBarButtonItemStyleDone target:self action:@selector(rightClick)];
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"弹出" style:UIBarButtonItemStyleDone target:self action:@selector(leftClick)];

    //遮罩层
    _myview=[[myView alloc]initWithFrame:CGRectMake(,-self.view.bounds.size.height, self.view.bounds.size.width, self.view.bounds.size.height)];
    _myview.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.1f];
    //为遮罩层添加手势识别 可以点击遮罩层空白处隐藏视图
    UIGestureRecognizer *tapgesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapclick)];
    _myview.userInteractionEnabled=YES;
    [_myview addGestureRecognizer:tapgesture];

    //设置DatePicker
    _dataPicker=[[UIDatePicker alloc]init];
    _dataPicker.frame=CGRectMake(, , , );
//    datepicker.backgroundColor=[UIColor grayColor];
    [_myview addSubview:_dataPicker];

    //设置DatePicker上面的视图
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(, , self.view.bounds.size.width, )];
    view.backgroundColor=[UIColor blueColor];
    UIButton *btnright=[UIButton buttonWithType:UIButtonTypeSystem];
    [btnright setTitle:@"确定" forState:UIControlStateNormal];
    [btnright addTarget:self action:@selector(btnrightClick:) forControlEvents:UIControlEventTouchUpInside];
    btnright.frame=CGRectMake(self.view.bounds.size.width-, , , );
    [view addSubview:btnright];
    [_myview addSubview:view];
    [self.view addSubview:_myview];
}
-(void)leftClick
{
    //下落动画 时间短一些
   [UIView beginAnimations:@"text" context:nil];
    [UIView setAnimationDelay:];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.3];
    _myview.frame=CGRectMake(,, self.view.bounds.size.width, self.view.bounds.size.height);
    [UIView commitAnimations];

    //恢复动画 时间长一些
    [UIView beginAnimations:@"text" context:nil];
    [UIView setAnimationDelay:];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    [UIView setAnimationDuration:0.5];
    _myview.frame=CGRectMake(,, self.view.bounds.size.width, self.view.bounds.size.height);
    [UIView commitAnimations];

}
-(void)tapclick
{
    [UIView beginAnimations:@"text" context:nil];
    [UIView setAnimationDelay:];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    [UIView setAnimationDuration:0.3];
    _myview.frame=CGRectMake(, -self.view.bounds.size.height, self.view.bounds.size.width, self.view.bounds.size.height);
    [UIView commitAnimations];
}
-(void)btnrightClick:(id)sender
{
    NSLog(@"%@",_dataPicker.date);
    [self tapclick];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

我们稍加改动就可以变成从底部弹出视图 这样就完成了闪购模块 宝贝详情中的选择规格的功能

#import "ViewController.h"
#import "PageViewController.h"
#import "myView.h"

@interface ViewController ()
@property(nonatomic,strong) myView *myview;
@property(nonatomic,strong) UIDatePicker *dataPicker;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"预览" style:UIBarButtonItemStyleDone target:self action:@selector(rightClick)];
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"弹出" style:UIBarButtonItemStyleDone target:self action:@selector(leftClick)];

    //遮罩层
    _myview=[[myView alloc]initWithFrame:CGRectMake(,self.view.bounds.size.height, self.view.bounds.size.width, self.view.bounds.size.height)];
    _myview.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.1f];
    //为遮罩层添加手势识别 可以点击遮罩层空白处隐藏视图
    UIGestureRecognizer *tapgesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapclick)];
    _myview.userInteractionEnabled=YES;
    [_myview addGestureRecognizer:tapgesture];

    //设置DatePicker
    _dataPicker=[[UIDatePicker alloc]init];
    _dataPicker.frame=CGRectMake(, self.view.bounds.size.height-, , );
//    datepicker.backgroundColor=[UIColor grayColor];
    [_myview addSubview:_dataPicker];

    //设置DatePicker上面的视图
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(, self.view.bounds.size.height-, self.view.bounds.size.width, )];
    view.backgroundColor=[UIColor blueColor];
    UIButton *btnright=[UIButton buttonWithType:UIButtonTypeSystem];
    [btnright setTitle:@"确定" forState:UIControlStateNormal];
    [btnright addTarget:self action:@selector(btnrightClick:) forControlEvents:UIControlEventTouchUpInside];
    btnright.frame=CGRectMake(self.view.bounds.size.width-, , , );
    [view addSubview:btnright];
    [_myview addSubview:view];
    [self.view addSubview:_myview];
}
-(void)leftClick
{
    //下落动画 时间短一些
   [UIView beginAnimations:@"text" context:nil];
    [UIView setAnimationDelay:];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.3];
    _myview.frame=CGRectMake(,, self.view.bounds.size.width, self.view.bounds.size.height);
    [UIView commitAnimations];

//    //恢复动画 时间长一些
//    [UIView beginAnimations:@"text" context:nil];
//    [UIView setAnimationDelay:0];
//    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
//    [UIView setAnimationDuration:0.5];
//    _myview.frame=CGRectMake(0,0, self.view.bounds.size.width, self.view.bounds.size.height);
//    [UIView commitAnimations];

}
-(void)tapclick
{
    [UIView beginAnimations:@"text" context:nil];
    [UIView setAnimationDelay:];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    [UIView setAnimationDuration:0.3];
    _myview.frame=CGRectMake(, self.view.bounds.size.height, self.view.bounds.size.width, self.view.bounds.size.height);
    [UIView commitAnimations];
}
-(void)btnrightClick:(id)sender
{
    NSLog(@"%@",_dataPicker.date);
    [self tapclick];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

上面的导航控制器并未被遮罩 ,这样添加时才能使导航控制器遮罩[[UIApplication sharedApplication].keyWindow  addSubview:_myview];

//
//  ViewController.m
//  PhotoBrower
//
//  Created by City--Online on 15/6/16.
//  Copyright (c) 2015年 City--Online. All rights reserved.
//
#define WIDTH self.view.bounds.size.width
#define HEIGHT self.view.bounds.size.height
#define SCREENWIDTH  [UIScreen mainScreen].bounds.size.width
#define SCREENHEIGHT [UIScreen mainScreen].bounds.size.height

#import "ViewController.h"
#import "PageViewController.h"
#import "ImageViewController.h"
#import "myView.h"

@interface ViewController ()
@property(nonatomic,strong) myView *myview;
@property(nonatomic,strong) UIDatePicker *dataPicker;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

//    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"预览" style:UIBarButtonItemStyleDone target:self action:@selector(rightClick)];
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"弹出" style:UIBarButtonItemStyleDone target:self action:@selector(leftClick)];

    //遮罩层
    _myview=[[myView alloc]initWithFrame:CGRectMake(,SCREENHEIGHT, WIDTH, SCREENHEIGHT)];
    _myview.backgroundColor = [UIColor colorWithWhite:0.5 alpha:0.1f];
    //为遮罩层添加手势识别 可以点击遮罩层空白处隐藏视图
    UIGestureRecognizer *tapgesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapclick)];
    _myview.userInteractionEnabled=YES;
    [_myview addGestureRecognizer:tapgesture];

    //设置DatePicker
    _dataPicker=[[UIDatePicker alloc]init];
    _dataPicker.frame=CGRectMake(, SCREENHEIGHT-, , );
    //    datepicker.backgroundColor=[UIColor grayColor];
    [_myview addSubview:_dataPicker];

    //设置DatePicker上面的视图
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(, SCREENHEIGHT-, WIDTH, )];
    view.backgroundColor=[UIColor blueColor];
    UIButton *btnright=[UIButton buttonWithType:UIButtonTypeSystem];
    [btnright setTitle:@"确定" forState:UIControlStateNormal];
    [btnright addTarget:self action:@selector(btnrightClick:) forControlEvents:UIControlEventTouchUpInside];
    btnright.frame=CGRectMake(self.view.bounds.size.width-, , , );
    [view addSubview:btnright];
    [_myview addSubview:view];
    [[UIApplication sharedApplication].keyWindow  addSubview:_myview];
//    [self.view addSubview:_myview];
//    [[UIApplication sharedApplication].delegate.window addSubview:_myview];
}
-(void)leftClick
{
    //下落动画 时间短一些
    [UIView beginAnimations:@"text" context:nil];
    [UIView setAnimationDelay:];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.3];
    _myview.frame=CGRectMake(,, self.view.bounds.size.width, SCREENHEIGHT);
    [UIView commitAnimations];

    //恢复动画 时间长一些
//    [UIView beginAnimations:@"text" context:nil];
//    [UIView setAnimationDelay:0];
//    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
//    [UIView setAnimationDuration:0.5];
//    _myview.frame=CGRectMake(0,0, self.view.bounds.size.width, self.view.bounds.size.height);
//    [UIView commitAnimations];

//    PageViewController *pageVc=[[PageViewController alloc]init];
//    pageVc.hidesBottomBarWhenPushed=YES;
////    [self presentViewController:pageVc animated:YES completion:nil];
//    [self.navigationController pushViewController:pageVc animated:YES];

}
-(void)tapclick
{
    [UIView beginAnimations:@"text" context:nil];
    [UIView setAnimationDelay:];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    [UIView setAnimationDuration:0.3];
    _myview.frame=CGRectMake(, SCREENHEIGHT, self.view.bounds.size.width, SCREENHEIGHT);
    [UIView commitAnimations];
}
-(void)btnrightClick:(id)sender
{
    NSLog(@"%@",_dataPicker.date);
    [self tapclick];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end

IOS项目之弹出动画一的更多相关文章

  1. IOS项目之弹出动画终结篇

    在之前写过IOS项目之弹出动画一.IOS项目之弹出动画二.IOS项目之弹出动画三,今天来一个终极封装已经上传到Github上弹出动画总结篇UIPopoverTableView. UIPopoverTa ...

  2. IOS项目之弹出动画二

    在IOS项目之弹出动画一中只是实现也功能,并没有体现面向对象的思想 ,今天就试着把它封装了一下,弹出视图的内容可以根据自定义,此处只是用UIDatePicker来演示 我把它传到了GitHub上    ...

  3. IOS项目之弹出动画三

    前面写了弹出动画两个,今天做商城时又用到了,看着这个用着蛮普遍的,所以记了下来 // // mallMoreView.h // XQB // // Created by City--Online on ...

  4. ios等待ualertview弹出动画完成后再跳转至其他页面

    [self performSelector:@selector(popView:) withObject:nil afterDelay:2.0];

  5. 阶段一:为View设置阴影和弹出动画(天气应用)

    “阶段一”是指我第一次系统地学习Android开发.这主要是对我的学习过程作个记录. 上一篇阶段一:通过网络请求,获得并解析JSON数据(天气应用)完成了应用的核心功能,接下来就要对它进行优化.今天我 ...

  6. mac关闭渐隐和弹出动画效果

    苹果系统应用程序的窗口和对话框每次使用的时候都有华丽的特效,但是如果你感觉这种特效显得有点慢(MacGG闲的蛋疼),那该如何取消掉他呢? 方法很简单,打开"终端"(Finder-& ...

  7. 清除ios系统alert弹出框的域名

    清除ios系统alert弹出框的域名 <script> window.alert = function(name) { var iframe = document.createElemen ...

  8. iOS 15 无法弹出授权弹框之解决方案---Your app uses the AppTrackingTransparency framework, but we are unable to locate the App Tracking Transparency permission request when reviewed on iOS 15.0

    2021年9月30日下午:我正愉快的期盼着即将到来的国庆假期,时不时刷新下appstoreconnect的网址,28号就提上去的包,今天还在审核中....由于这个版本刚升级的xcode系统和新出的iO ...

  9. WPF制作子窗体的弹出动画效果

    创建一个WPF应用程序WpfApplication1,新建个窗体DialogWin <Windowx:Class="WpfApplication1.DialogWin" xm ...

随机推荐

  1. <mvc:annotation-driven />到底帮我们做了啥

    一句 <mvc:annotation-driven />实际做了以下工作:(不包括添加自己定义的拦截器) 我们了解这些之后,对Spring3 MVC的控制力就更强大了,想改哪就改哪里. s ...

  2. mac下的抓包工具 -- Charles

    # 背景 换了mac电脑,

  3. Ajax异步请求阻塞情况的解决办法

    最近使用ExtJs4的mvc模式在开发了在线漫画的后台,因为异步请求比较多,有的回应时间长,有点短.我发现在多次并发的情况下,会造成阻塞的情况.也就是说如果回应时间长的请求还在进行中,短的请求却被挂起 ...

  4. UEditor编辑器两个版本任意文件上传漏洞分析

    0x01 前言 UEditor是由百度WEB前端研发部开发的所见即所得的开源富文本编辑器,具有轻量.可定制.用户体验优秀等特点 ,被广大WEB应用程序所使用:本次爆出的高危漏洞属于.NET版本,其它的 ...

  5. 点分治&&动态点分治学习笔记

    突然发现网上关于点分和动态点分的教程好像很少……蒟蒻开篇blog记录一下吧……因为这是个大傻逼,可能有很多地方写错,欢迎在下面提出 参考文献:https://www.cnblogs.com/LadyL ...

  6. JavaScript基础流程控制(3)

    day51 参考:https://www.cnblogs.com/liwenzhou/p/8004649.html for循环 while循环 三元运算 a>b条件成立,选a,不成立选b

  7. python爬虫2——下载文件(中华网图片库下载)

    # -*- coding: utf-8 -*- import requests import re import sys reload(sys) sys.setdefaultencoding('utf ...

  8. elasticsearch5.x安装中一些问题的解决办法

    1.root超级用户不能正常启动 由于elasticsearch2.0版本以后不能使用root来启动,所以需要创建一个普通用户来启动. [root@bogon ~]# groupadd elastic ...

  9. 逆向工程生成的Mapper.xml以及*Example.java详解

    逆向工程生成的接口中的方法详解 在我上一篇的博客中讲解了如何使用Mybayis逆向工程针对单表自动生成mapper.java.mapper.xml.实体类,今天我们先针对mapper.java接口中的 ...

  10. 数据结构---散列表查找(哈希表)概述和简单实现(Java)

    散列表查找定义 散列技术是在记录的存储位置和它的关键字之间建立一个确定的对应关系f,是的每个关键字key对应一个存储位置f(key).查找时,根据这个确定的对应关系找到给定值的key的对应f(key) ...