第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

導(dǎo)航控制器自定義過(guò)渡動(dòng)畫

導(dǎo)航控制器自定義過(guò)渡動(dòng)畫

iOS
catspeake 2019-12-09 14:15:35
我一直在遵循一些教程來(lái)創(chuàng)建自定義動(dòng)畫,同時(shí)從一個(gè)視圖過(guò)渡到另一個(gè)視圖。我的測(cè)試項(xiàng)目從這里使用自定義segue 可以正常工作,但是有人告訴我,不再鼓勵(lì)在自定義segue中進(jìn)行自定義動(dòng)畫,我應(yīng)該使用UIViewControllerAnimatedTransitioning。我遵循了一些使用此協(xié)議的教程,但所有教程都是關(guān)于模式表示的(例如本教程)。我想做的是在導(dǎo)航控制器樹(shù)中進(jìn)行推送選擇,但是當(dāng)我嘗試對(duì)顯示(推送)選擇執(zhí)行相同的操作時(shí),它將不再起作用。請(qǐng)告訴我在導(dǎo)航控制器中進(jìn)行從一個(gè)視圖到另一個(gè)視圖的自定義過(guò)渡動(dòng)畫的正確方法。而且無(wú)論如何,我可以對(duì)所有過(guò)渡動(dòng)畫使用一種方法嗎?如果有一天我想做同樣的動(dòng)畫,但是最終不得不重復(fù)兩次代碼以進(jìn)行模態(tài)與控制器轉(zhuǎn)換,那將很尷尬。
查看完整描述

3 回答

?
幕布斯7119047

TA貢獻(xiàn)1794條經(jīng)驗(yàn) 獲得超8個(gè)贊

要使用導(dǎo)航控制器(UINavigationController)進(jìn)行自定義轉(zhuǎn)換,您應(yīng)該:


定義您的視圖控制器以符合UINavigationControllerDelegate協(xié)議。例如,您可以在視圖控制器的.m文件中具有私有類擴(kuò)展名,該擴(kuò)展名指定對(duì)此協(xié)議的符合性:


@interface ViewController () <UINavigationControllerDelegate>


@end

確保您確實(shí)將視圖控制器指定為導(dǎo)航控制器的委托:


- (void)viewDidLoad {

    [super viewDidLoad];


    self.navigationController.delegate = self;

}

實(shí)現(xiàn)animationControllerForOperation您的視圖控制器:


- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController

                                  animationControllerForOperation:(UINavigationControllerOperation)operation

                                               fromViewController:(UIViewController*)fromVC

                                                 toViewController:(UIViewController*)toVC

{

    if (operation == UINavigationControllerOperationPush)

        return [[PushAnimator alloc] init];


    if (operation == UINavigationControllerOperationPop)

        return [[PopAnimator alloc] init];


    return nil;

}

實(shí)現(xiàn)用于推送和彈出動(dòng)畫的動(dòng)畫制作器,例如:


@interface PushAnimator : NSObject <UIViewControllerAnimatedTransitioning>


@end


@interface PopAnimator : NSObject <UIViewControllerAnimatedTransitioning>


@end


@implementation PushAnimator


- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext

{

    return 0.5;

}


- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext

{

    UIViewController* toViewController   = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];


    [[transitionContext containerView] addSubview:toViewController.view];


    toViewController.view.alpha = 0.0;


    [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{

        toViewController.view.alpha = 1.0;

    } completion:^(BOOL finished) {

        [transitionContext completeTransition:![transitionContext transitionWasCancelled]];

    }];

}


@end


@implementation PopAnimator


- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext

{

    return 0.5;

}


- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext

{

    UIViewController* toViewController   = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];

    UIViewController* fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];


    [[transitionContext containerView] insertSubview:toViewController.view belowSubview:fromViewController.view];


    [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{

        fromViewController.view.alpha = 0.0;

    } completion:^(BOOL finished) {

        [transitionContext completeTransition:![transitionContext transitionWasCancelled]];

    }];

}


@end

確實(shí)會(huì)出現(xiàn)淡入淡出的過(guò)渡,但是您應(yīng)該隨心所欲地自定義動(dòng)畫。


如果您想處理交互式手勢(shì)(例如,從左向右滑動(dòng)本機(jī)滑動(dòng)之類的東西),則必須實(shí)現(xiàn)一個(gè)交互控制器:


定義交互控制器(符合的對(duì)象UIViewControllerInteractiveTransitioning)的屬性:


@property (nonatomic, strong) UIPercentDrivenInteractiveTransition *interactionController;

這UIPercentDrivenInteractiveTransition是一個(gè)不錯(cuò)的對(duì)象,它會(huì)根據(jù)手勢(shì)的完成程度來(lái)繁瑣地更新自定義動(dòng)畫。


將手勢(shì)識(shí)別器添加到視圖。在這里,我只是實(shí)現(xiàn)左手勢(shì)識(shí)別器來(lái)模擬彈出:


UIScreenEdgePanGestureRecognizer *edge = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFromLeftEdge:)];

edge.edges = UIRectEdgeLeft;

[view addGestureRecognizer:edge];

實(shí)現(xiàn)手勢(shì)識(shí)別處理程序:


/** Handle swipe from left edge

 *

 * This is the "action" selector that is called when a left screen edge gesture recognizer starts.

 *

 * This will instantiate a UIPercentDrivenInteractiveTransition when the gesture starts,

 * update it as the gesture is "changed", and will finish and release it when the gesture

 * ends.

 *

 * @param   gesture       The screen edge pan gesture recognizer.

 */


- (void)handleSwipeFromLeftEdge:(UIScreenEdgePanGestureRecognizer *)gesture {

    CGPoint translate = [gesture translationInView:gesture.view];

    CGFloat percent   = translate.x / gesture.view.bounds.size.width;


    if (gesture.state == UIGestureRecognizerStateBegan) {

        self.interactionController = [[UIPercentDrivenInteractiveTransition alloc] init];

        [self popViewControllerAnimated:TRUE];

    } else if (gesture.state == UIGestureRecognizerStateChanged) {

        [self.interactionController updateInteractiveTransition:percent];

    } else if (gesture.state == UIGestureRecognizerStateEnded) {

        CGPoint velocity = [gesture velocityInView:gesture.view];

        if (percent > 0.5 || velocity.x > 0) {

            [self.interactionController finishInteractiveTransition];

        } else {

            [self.interactionController cancelInteractiveTransition];

        }

        self.interactionController = nil;

    }

}

在導(dǎo)航控制器委托中,還必須實(shí)現(xiàn)interactionControllerForAnimationController委托方法


- (id<UIViewControllerInteractiveTransitioning>)navigationController:(UINavigationController *)navigationController

                         interactionControllerForAnimationController:(id<UIViewControllerAnimatedTransitioning>)animationController {

    return self.interactionController;

}

如果您在Google上搜索“ UINavigationController自定義過(guò)渡教程”,那么您將獲得很多成功?;騾㈤哤WDC 2013 Custom Transitions視頻。


查看完整回答
反對(duì) 回復(fù) 2019-12-09
?
猛跑小豬

TA貢獻(xiàn)1858條經(jīng)驗(yàn) 獲得超8個(gè)贊

您可能想在之前添加以下代碼 addSubview


  toViewController.view.frame = [transitionContext finalFrameForViewController:toViewController];

來(lái)自另一個(gè)問(wèn)題,在iOS 9上使用navigationcontroller為推送動(dòng)畫進(jìn)行自定義轉(zhuǎn)換


從Apple的finalFrameForViewController文檔中:


返回指定視圖控制器視圖的結(jié)束幀矩形。


此方法返回的矩形表示過(guò)渡結(jié)束時(shí)相應(yīng)視圖的大小。對(duì)于演示過(guò)程中涉及的視圖,此方法返回的值可能是CGRectZero,但也可能是有效的框架矩形。


查看完整回答
反對(duì) 回復(fù) 2019-12-09
  • 3 回答
  • 0 關(guān)注
  • 576 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)