欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

UIKit框架(10)自定義modal過渡效果

上一篇文章介紹了如何進(jìn)行modal方式的頁面切換

創(chuàng)新互聯(lián)建站專注于阿魯科爾沁企業(yè)網(wǎng)站建設(shè),成都響應(yīng)式網(wǎng)站建設(shè),商城網(wǎng)站建設(shè)。阿魯科爾沁網(wǎng)站建設(shè)公司,為阿魯科爾沁等地區(qū)提供建站服務(wù)。全流程按需制作網(wǎng)站,專業(yè)設(shè)計,全程項目跟蹤,創(chuàng)新互聯(lián)建站專業(yè)和態(tài)度為您提供的服務(wù)

自定義的目的控制器在modal切換時完全覆蓋源控制器,本篇文章介紹如何實現(xiàn)一個自定義的過渡效果

實現(xiàn)的效果描述:

    目的控制器:占據(jù)屏幕的二分之一大小,且居中,并在源控制器上覆蓋著一個陰影效果,點擊陰影時目的控制器返回

  • UIPresentationController

用于描述目的控制器通過modal方式切換的過渡效果

實現(xiàn)其子類,可以自定義出特殊的效果

實現(xiàn)步驟:

  1. 定義過渡效果:實現(xiàn)UIPresentationController子類

  2. 目的控制器,遵循過渡協(xié)議,設(shè)置過渡控制器對象

  3. 源控制器進(jìn)行modal切換

UIPresentationController的屬性:

@property(nonatomic, retain, readonly) UIViewController *presentedViewController   //目的控制器
@property(nonatomic, retain, readonly) UIViewController*presentingViewController   //源控制器
- (UIView *)presentedView  //目的view
     @property(nonatomic, readonly) UIView *containerView  //源view

  • UIPresentationController的子類應(yīng)重寫的方法

1)init方法,可以創(chuàng)建其他輔助過渡效果的view

- (instancetype)initWithPresentedViewController:(UIViewController*)presentedViewController presentingViewController:(UIViewController*)presentingViewController

    如:

- (instancetype)initWithPresentedViewController:(UIViewController*)presentedViewController presentingViewController:(UIViewController*)presentingViewController {    
    if ( self = [super initWithPresentedViewController:presentedViewController presentingViewController:presentingViewController] ) {
        _shadowBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        //陰影按鈕的初始狀態(tài)是隱藏的
        _shadowBtn.backgroundColor = [UIColor grayColor];
        _shadowBtn.alpha = 0.f;
    }
}

2)重寫presentationTransitionWillbegin方法,定義實現(xiàn)過渡效果

- (void)presentationTransitionWillBegin

    如:

- (void)presentationTransitionWillBegin
{
    [self.containerView addSubview:_shadowBtn];
    [self.containerView addSubview:self.presentedView];
    _shadowBtn.frame = self.containerView.bounds;
    id <UIViewControllerTransitionCoordinator> coordinate = self.presetingViewController.transitionCoordinator;
    [coordinate animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
        _shadowBtn.alpha = 0.5;
    } completion:nil];
}

    使用到UIViewController的transitionCoordinator,表示過渡效果的協(xié)助器

     協(xié)助器的animateAlongsideTransition方法定義過渡期間的動畫效果

3)重寫presentationTransitionDidEnd方法,定義過渡效果后的清理工作。

    特別是過渡未完成時的清理動作

- (void)presentationTransitionDidEnd:(BOOL)completed
- (void)presentationTransitionDidEnd:(BOOL)completed
{
    if ( !completed ) {
        [_shadowBtn removeFromSuperview];
    }
}

4)重寫frameOfPresentedViewInContainerView,設(shè)置被顯示視圖的frame

- (CGRect)frameOfPresentedViewInContainerView
- (CGRect)frameOfPresentedViewInContainerView
{
    CGFloat x, y, w, h;
    w = self.containerView.frame.size.width/2;
    h = self.containerView.frame.size.height/2;
    x = self.containerView.frame.size.width/4;
    y = self.containerView.frame.size.height/4;
    return CGRectMake(x, y, w, h);
}

5)重寫dismissTransitionWillBegin方法,設(shè)置返回的過渡效果

- (void)dismissalTransitionWillBegin
- (void)dismissalTransitionWillBegin
{
    id<UIViewControllerTransitionCoordinator> coordinator = self.presetingViewController.transitionCoordinator;
    [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonull context) {
        _shadowBtn.alpha = 0.01;
    } completion:nil];
}

6)重寫dismissalTransitionDidEnd方法,執(zhí)行清理動作

- (void)dismissalTransitionDidEnd:(BOOL)completed
- (void)dismissalTransitionDidEnd:(BOOL)completed
{
    if ( completed ) {
        [_shadowView removeFromSuperview];
    }
}

     

  • 目的控制器設(shè)置過渡效果

目的控制器遵循代理協(xié)議

@interface AMDestViewController () <UIViewControllerTransitioningDelegate>

設(shè)置代理

self.transitioningDelegate = self;

實現(xiàn)代理方法

- (UIPresetationController *) presentationControllerForPresentedViewController:(UIViewController*) presented presentingViewController:(UIViewController*) presenting sourceViewController:(UIViewController*) source
{
    return [[AMPresentationController alloc] initWithPresentedViewController:presented presentingViewController:presenting];
}

  • 源控制器進(jìn)行modal切換

iOS8.0開始支持這種自定義的過渡效果,主要要設(shè)置目的控制器的modalPresentationStyle為自定義。

這種切換方式,在iPhone和iPad上都是可用的。

AMDestViewController * vc = [[AMDestViewController alloct] init];
vc.modalPresentationStyle = UIModalPresentationCustom;
[self presentViewController:vc animated:YES completion:nil];

當(dāng)前名稱:UIKit框架(10)自定義modal過渡效果
文章分享:http://aaarwkj.com/article12/iioegc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供ChatGPT網(wǎng)站排名、標(biāo)簽優(yōu)化、電子商務(wù)、企業(yè)建站、網(wǎng)站改版

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)
国内校园性猛交视频网站| 国产偷人伦激情在线观看| 亚洲老熟女老妇老女人| 亚洲情欲一级片日韩欧美| 日韩国产乱码一区中文字幕| 亚洲国产成在人网站天堂| 国产传媒在线免费播放| 日本免费一区二区三区手机在线| 国产精品久久99粉嫩| 丰满人妻一区二区三区色| 国产黄片大秀在线观看| 午夜在线成人免费观看| 中文字幕乱码高清欧美日韩| 国产精品一区二区啪啪| 国产一区二区三区本色| 欧美亚洲精品二区久久久| 日韩欧美中文字幕区| 五月激情开心久久婷婷| 黄色录像免费看中文字幕| 粉嫩av蜜臀一区二区三区| 国产高清剧情在线观看| 日韩欧美乱码一区二区| 日韩免费精品一区二区| 国语对白刺激真实精品| 免费无遮挡午夜视频网站| 亚洲日本欧美激情综合| 18末年禁止观看免费软件| 国产真实内射在线观看| 18禁在线免费观看网站| 国产成人av网站在线观看| 国产精品成人大片在线播放| 久久这里有精品免费观看| 极品美女粉嫩啪啪高潮| 日韩精品不卡在线观看| 91国内精品手机在线高清| 天天操时时操夜夜操| 18禁黄网站免费观看在线| 亚洲人妻激情一区二区| 久国产亚洲精品久久久极品| 丰满人妻侵犯中文字幕| 日韩欧美高清一区二区|