IOS项目之弹出动画一

小区宝首页导航栏左边有一个物业按钮,点击时会出现一个视图动画,之前用的是一个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(0,-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(0, 40, 0, 0);
//    datepicker.backgroundColor=[UIColor grayColor];
    [_myview addSubview:_dataPicker];
    
    //设置DatePicker上面的视图
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 40)];
    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-40, 0, 40, 40);
    [view addSubview:btnright];
    [_myview addSubview:view];
    [self.view addSubview:_myview];
}
-(void)leftClick
{
    //下落动画 时间短一些
   [UIView beginAnimations:@"text" context:nil];
    [UIView setAnimationDelay:0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.3];
    _myview.frame=CGRectMake(0,40, 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:0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    [UIView setAnimationDuration:0.3];
    _myview.frame=CGRectMake(0, -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(0,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(0, self.view.bounds.size.height-300, 0, 0);
//    datepicker.backgroundColor=[UIColor grayColor];
    [_myview addSubview:_dataPicker];
    
    //设置DatePicker上面的视图
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, self.view.bounds.size.height-340, self.view.bounds.size.width, 40)];
    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-40, 0, 40, 40);
    [view addSubview:btnright];
    [_myview addSubview:view];
    [self.view addSubview:_myview];
}
-(void)leftClick
{
    //下落动画 时间短一些
   [UIView beginAnimations:@"text" context:nil];
    [UIView setAnimationDelay:0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.3];
    _myview.frame=CGRectMake(0,0, 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:0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    [UIView setAnimationDuration:0.3];
    _myview.frame=CGRectMake(0, 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(0,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(0, SCREENHEIGHT-220, 0, 0);
    //    datepicker.backgroundColor=[UIColor grayColor];
    [_myview addSubview:_dataPicker];
    
    //设置DatePicker上面的视图
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, SCREENHEIGHT-260, WIDTH, 40)];
    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-40, 0, 40, 40);
    [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:0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.3];
    _myview.frame=CGRectMake(0,0, 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:0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    [UIView setAnimationDuration:0.3];
    _myview.frame=CGRectMake(0, 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

 

转载于:https://www.cnblogs.com/5ishare/p/4583448.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值