您的位置:首页 > 移动开发 > IOS开发

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];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: