iOS 简单实现类似于小说阅读滑动分页效果
2018-02-26 16:40
555 查看
废话不多说上代码,我们要创建一个UIViewController
typedef
enum : NSUInteger {
Fade =
1,
//淡入淡出
Push,
//推挤
Reveal,
//揭开
MoveIn,
//覆盖
Cube,
//立方体
SuckEffect,
//吮吸
OglFlip,
//翻转
RippleEffect,
//波纹
PageCurl,
//翻页
PageUnCurl,
//反翻页
CameraIrisHollowOpen,
//开镜头
CameraIrisHollowClose,
//关镜头
CurlDown,
//下翻页
CurlUp,
//上翻页
FlipFromLeft, <
4000
span style="font-size:11px;line-height:normal;color:rgb(0,132,0);">
//左翻转
FlipFromRight,
//右翻转
} AnimationType;
各种分页效果。
@interface
ViewController (){
NSInteger _count;//翻到的第几页
NSInteger _sum;//页面总数
NSArray *_arr;//设置页面背景色
}
- (void)viewDidLoad {
[super
viewDidLoad];
_sum =
20;
self.view.backgroundColor
= [UIColor
whiteColor];
_arr =
@[[UIColor
redColor],[UIColor
greenColor],[UIColor
blueColor]];
NSLog(@"------------------?------------第%ld页",(long)_count);
[self
rootViewAddUISwipeGestureRecognizer];
}
-(void)rootViewAddUISwipeGestureRecognizer{
UISwipeGestureRecognizer *fromRightSwip = [[UISwipeGestureRecognizer
alloc]
initWithTarget:self
action:@selector(nextPage)];
fromRightSwip.direction
= UISwipeGestureRecognizerDirectionLeft;
[self.view
addGestureRecognizer:fromRightSwip];
UISwipeGestureRecognizer *fromLeftSwip = [[UISwipeGestureRecognizer
alloc]
initWithTarget:self
action:@selector(forwardPage)];
fromLeftSwip.direction
= UISwipeGestureRecognizerDirectionRight;
[self.view
addGestureRecognizer:fromLeftSwip];
}
//实现滑动事件
-(void)nextPage{
self.view.backgroundColor
= _arr[arc4random()%3];
if (_count<_sum-1)
{
NSString *subtypeString;
subtypeString =
kCATransitionFromRight;
[self
transitionWithType:@"push"
WithSubtype:subtypeString
ForView:self.view];
_count =
_count +
1;
} else {
_count =
_sum -
1;
}
NSLog(@"+++++++++++++++++++?+++++++++++++++第%ld页",(long)_count);
}
-(void)forwardPage{<
c3a9
/p>
self.view.backgroundColor
= _arr[arc4random()%3];
if (_count>0 ) {
NSString *subtypeString;
subtypeString =
kCATransitionFromLeft;
[self
transitionWithType:@"push"
WithSubtype:subtypeString
ForView:self.view];
_count =
_count -
1;
} else {
_count =
0;
}
NSLog(@"------------------?------------第%ld页",(long)_count);
}
#pragma mark CATransition动画实现
/**
* 动画效果实现
*/
- (void) transitionWithType:(NSString *) type WithSubtype:(NSString
*) subtype ForView : (UIView *) rootview {
//创建CATransition对象
CATransition *animation = [CATransition
animation];
animation.duration =
0.5f;
animation.type = type;
if (subtype !=
nil) {
animation.subtype = subtype;
}
animation.timingFunction
= UIViewAnimationOptionCurveEaseInOut;
[rootview.layer
addAnimation:animation
forKey:@"animation"];
}
- (void)didReceiveMemoryWarning {
[super
didReceiveMemoryWarning];
}
typedef
enum : NSUInteger {
Fade =
1,
//淡入淡出
Push,
//推挤
Reveal,
//揭开
MoveIn,
//覆盖
Cube,
//立方体
SuckEffect,
//吮吸
OglFlip,
//翻转
RippleEffect,
//波纹
PageCurl,
//翻页
PageUnCurl,
//反翻页
CameraIrisHollowOpen,
//开镜头
CameraIrisHollowClose,
//关镜头
CurlDown,
//下翻页
CurlUp,
//上翻页
FlipFromLeft, <
4000
span style="font-size:11px;line-height:normal;color:rgb(0,132,0);">
//左翻转
FlipFromRight,
//右翻转
} AnimationType;
各种分页效果。
@interface
ViewController (){
NSInteger _count;//翻到的第几页
NSInteger _sum;//页面总数
NSArray *_arr;//设置页面背景色
}
- (void)viewDidLoad {
[super
viewDidLoad];
_sum =
20;
self.view.backgroundColor
= [UIColor
whiteColor];
_arr =
@[[UIColor
redColor],[UIColor
greenColor],[UIColor
blueColor]];
NSLog(@"------------------?------------第%ld页",(long)_count);
[self
rootViewAddUISwipeGestureRecognizer];
}
-(void)rootViewAddUISwipeGestureRecognizer{
UISwipeGestureRecognizer *fromRightSwip = [[UISwipeGestureRecognizer
alloc]
initWithTarget:self
action:@selector(nextPage)];
fromRightSwip.direction
= UISwipeGestureRecognizerDirectionLeft;
[self.view
addGestureRecognizer:fromRightSwip];
UISwipeGestureRecognizer *fromLeftSwip = [[UISwipeGestureRecognizer
alloc]
initWithTarget:self
action:@selector(forwardPage)];
fromLeftSwip.direction
= UISwipeGestureRecognizerDirectionRight;
[self.view
addGestureRecognizer:fromLeftSwip];
}
//实现滑动事件
-(void)nextPage{
self.view.backgroundColor
= _arr[arc4random()%3];
if (_count<_sum-1)
{
NSString *subtypeString;
subtypeString =
kCATransitionFromRight;
[self
transitionWithType:@"push"
WithSubtype:subtypeString
ForView:self.view];
_count =
_count +
1;
} else {
_count =
_sum -
1;
}
NSLog(@"+++++++++++++++++++?+++++++++++++++第%ld页",(long)_count);
}
-(void)forwardPage{<
c3a9
/p>
self.view.backgroundColor
= _arr[arc4random()%3];
if (_count>0 ) {
NSString *subtypeString;
subtypeString =
kCATransitionFromLeft;
[self
transitionWithType:@"push"
WithSubtype:subtypeString
ForView:self.view];
_count =
_count -
1;
} else {
_count =
0;
}
NSLog(@"------------------?------------第%ld页",(long)_count);
}
#pragma mark CATransition动画实现
/**
* 动画效果实现
*/
- (void) transitionWithType:(NSString *) type WithSubtype:(NSString
*) subtype ForView : (UIView *) rootview {
//创建CATransition对象
CATransition *animation = [CATransition
animation];
animation.duration =
0.5f;
animation.type = type;
if (subtype !=
nil) {
animation.subtype = subtype;
}
animation.timingFunction
= UIViewAnimationOptionCurveEaseInOut;
[rootview.layer
addAnimation:animation
forKey:@"animation"];
}
- (void)didReceiveMemoryWarning {
[super
didReceiveMemoryWarning];
}
相关文章推荐
- webapp在ios中简单实现滑动,回弹,加速等效果
- webView 之 webapp在ios中简单实现滑动,回弹,加速等效果
- iOS实现简单的二级菜单效果
- Android基础学习总结(七)——简单实现新闻选项卡滑动效果(CoordinatorLayout+AppBarLayout+Toolbar+TabLayout+ViewPager大合成)
- 实现IOS版的抽屉效果(点击,拖拽滑动)
- ios: 仿照【ONE】应用中的阅读滑动效果
- ANDROID GridView 分页平滑滑动 效果的实现(基于android TV遥控器操作)
- Android滑动菜单特效实现,仿人人客户端侧滑效果,史上最简单的侧滑实现
- Android实现简单的分页效果
- Android滑动菜单特效实现,仿人人客户端侧滑效果,史上最简单的侧滑实现
- Android滑动菜单特效实现,仿人人客户端侧滑效果,史上最简单的侧滑实现
- Android滑动菜单特效实现,侧滑效果,史上最简单的侧滑实现
- Activity随手势滑动退出,及模糊Dialog(类似于IOS的效果)
- jquery实现最简单的滑动菜单效果代码
- jquery实现最简单的滑动菜单效果代码
- Android滑动菜单特效实现,仿人人客户端侧滑效果,史上最简单的侧滑实现
- 简单实现Ajax无刷新分页效果
- Android滑动菜单特效实现,仿人人客户端侧滑效果,史上最简单的侧滑实现
- iOS 简单动画效果实现的三种方式