UINavigationController push到第二界面,平移手势右滑可退回到第一界面

本文介绍了如何通过自定义UINavigationController,实现类似iOS系统默认的右滑平移手势退回上一个界面的功能。通过创建一个继承自UINavigationController的类,并在其中处理拖动手势,实现视图的平移和缩放动画效果。
摘要由CSDN通过智能技术生成

纯代码和storyboard都可以()

建一个继承自UINavigationController的类

以下是.m文件

//

//  PanGestureBaseViewController.m

//  TranslationEncapsulation

//

//  Created by 银羽2 on 15/12/27.

//  Copyright © 2015银羽2. All rights reserved.

//



#import "PanGestureBaseViewController.h"


#define kWindow [[UIApplication sharedApplication] keyWindow]

#define kScreenWidth self.view.bounds.size.width


static constfloat kDurationTime =0.3;

static constfloat kScaleValue =0.95;


@interface PanGestureBaseViewController ()

{

    CGPoint startTouch;//拖动开始时的位置

    BOOL isMoving; //是否在拖动中

    UIView *blackMask;

    UIImageView *lastScreenShotView;

}


@property (strong,nonatomic)UIView *backgroundView;//背景

@property (strong,nonatomic)NSMutableArray *screenShotsList;//存截


@end


@implementation PanGestureBaseViewController



- (void)viewDidLoad {

    [superviewDidLoad];

    //初始化数组

    self.screenShotsList = [NSMutableArrayarray];

    UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizeralloc]initWithTarget:selfaction:@selector(handlePanGesture:)];

    [self.viewaddGestureRecognizer:panGesture];

    self.navigationBar.hidden =YES;

    isMoving = NO;

}


-(void)addLastScreenShotView

{

    if (lastScreenShotView)[lastScreenShotViewremoveFromSuperview];

    UIImage *lastScreenShot = [self.screenShotsListlastObject];

    //把截图插入到backgoundView,并黑色的背景下面

    lastScreenShotView = [[UIImageViewalloc]initWithImage:lastScreenShot];

    [self.back

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值