zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

IOS项目之弹出动画终结篇

2023-09-14 08:57:59 时间

今天来一个终极封装已经上传到Github上弹出动画总结篇UIPopoverTableView

UIPopoverTableView也是在前面的几个基础上进行封装。如果对默认的动画效果不满意可以继承它,重写- (void)fadeIn和- (void)fadeOut方法在Github中也写了一个demo。

UIPopoverTableView本质还是一个TableView,只是在TableView的基础上增加了一些属性和方法,下面我把.H贴出来,介绍下怎么使用。


//

// UIPopoverTableView.h

// XQBCommunityApp

// Created by City--Online on 16/1/27.

// Copyright © 2016年 CityOnline_1. All rights reserved.

#import UIKit/UIKit.h 

#import Foundation/Foundation.h 

@class UIPopoverTableView;

@protocol PopoverTableViewDelegate NSObject 

@optional

//头部视图

-(UIView *)popTableHeadView:(UITableView *)tableView;

//顶部试图

-(UIView *)popTableFooterView:(UITableView *)tableView;

- (void)popoverTableViewCancel:(UITableView *)popTableView;

@interface UIPopoverTableView : UITableView

@property (nonatomic,strong) UIControl *overlayView;

@property (nonatomic,strong) UIView *contentView;

@property (nonatomic,assign) float contentViewCornerRadius;

@property (nonatomic, assign) id PopoverTableViewDelegate popoverDelegate;

//在父视图view的相对位置为Frame

-(void)showInView:(UIView*)view withFrame:(CGRect)frame;

//下面两个方法主要是为了子类定义弹入弹出动画

//显示的动画效果

- (void)fadeIn;

//显示的动画效果

- (void)fadeOut;

@end

1.PopoverTableViewDelegate协议中主要是头部、尾部和点击空白的代理方法。

2.属性

overlayView是背景层。

contentView是包括头部、尾部和中间的TableView,整个的弹出内容。

contentViewCornerRadius是设置contentView的边角。

对于有些可能要设置中间View的CornerRadius,可以设置UIPopoverTableView的CornerRadius,例如下面的效果图.

 

3.方法

- (void)fadeIn;- (void)fadeOut;主要是为了子类自定义contentView的弹入弹出效果。

UIPopoverTableView默认contentView的动画效果类似微信红包的效果。

如果要改变动画显示效果例如从底部弹出、或者从顶部拉出,可以继承UIPopoverTableView重现- (void)fadeIn;- (void)fadeOut;在Github中我是这样重写,主要还是对

contentView和overlayView操作。


- (void)fadeIn

 self.contentView.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width, self.contentView.frame.size.height);

 [UIView animateWithDuration:.35 animations:^{

 self.contentView.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height-self.contentView.frame.size.height, [UIScreen mainScreen].bounds.size.width, self.contentView.frame.size.height);

 } completion:^(BOOL finished) {

- (void)fadeOut{


[UIView animateWithDuration:.35 animations:^{ self.contentView.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width, self.contentView.frame.size.height); } completion:^(BOOL finished) { if (finished) { [self.overlayView removeFromSuperview]; [self.contentView removeFromSuperview]; }

UIPopoverTableView可以实现小区宝中的以下几个效果

 

对于这几次博客园管理员总是将我的博客移除首页,我表示遗憾。



社会主义 从.Net到iOS,在撸的道路上越走越远,工作之余经营着博客园http://www.cnblogs.com/5ishare,欢迎小伙伴(妹子更好)一起交流,谈谈人生理想。作为经常从网上索取免费资料的一员,要有回报回报的思想,也让更多的人少走弯路.