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

為了賬號安全,請及時綁定郵箱和手機立即綁定

仿照“豌豆莢一覽”做的iOS轉(zhuǎn)場動畫

標(biāo)簽:
iOS

豌豆荚一览的转场动画非常炫,尤其是点击一个新闻条目跳转到新闻正文的时候

于是我做了个类似的,放在了GitHub

动画

介绍一下主要实现:

从VC1(ViewController1)跳转到VC2的时候,主要是调用下面这个方法,这个方法有两个参数,一个是要显示的下一个ViewController,还有一个是,动画从那个方块开始(因为豌豆荚一览是从某个cell开始的动画)

- (void) animToNextViewController:(UIViewController*)viewController beginRect:(CGRect)beginFrame {
    UIWindow *window = [UIApplication sharedApplication].keyWindow;

    CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
    CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;

    UIView* shadowBack = [[UIView alloc]initWithFrame:window.bounds];
    shadowBack.backgroundColor = [UIColor blackColor];
    shadowBack.alpha = 0.7;
    [window addSubview:shadowBack];

    UIView* frontWhiteView = [[UIView alloc]initWithFrame:beginFrame];
    frontWhiteView.backgroundColor = [UIColor whiteColor];
    [window addSubview:frontWhiteView];

    NSTimeInterval timeInterval = 0.5;

    __weak __typeof(self) weakSelf = self;
    [UIView animateWithDuration:timeInterval/5 animations:^{
        frontWhiteView.frame = CGRectMake(0, screenHeight/2-18, screenWidth, 36);
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:4*timeInterval/5 animations:^{
            frontWhiteView.frame = CGRectMake(0, 0, screenWidth, screenHeight);
        } completion:^(BOOL finished) {
            UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:viewController];
            viewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
            nav.modalPresentationStyle = UIModalPresentationOverCurrentContext;

            [weakSelf presentViewController:nav animated:NO completion:^{
                [shadowBack removeFromSuperview];
                [frontWhiteView removeFromSuperview];
            }];
//            [self.navigationController pushViewController:viewController animated:NO];
//            [shadowBack removeFromSuperview];
//            [frontWhiteView removeFromSuperview];

        }];
    }];

    [UIView animateWithDuration:timeInterval animations:^{

        weakSelf.navigationController.view.transform = CGAffineTransformMakeScale(0.85, 0.85);

    } completion:^(BOOL finished) {

        weakSelf.navigationController.view.transform = CGAffineTransformIdentity;

    }];

}

这里做了一些操作,首先在window上,覆盖了一个半透明的黑色遮罩,然后又在window上覆盖了动画开始的白色方块。
之后通过动画,缩小再放大这个白色方块到铺满全屏,动画完成以后,presentViewController到下一个视图,注意presentViewController是不再需要动画了,所以传入NO
在这个动画同时,还有一个动画,它与上面的动画总时间相同,整个动画缩小了当前整个视图的(self.navigationController.view)的大小,有一种下沉的感觉,在动画结束的时候,这个时候下一个ViewController也已经覆盖到了当前视图上,所以恢复当前视图的大小

这里有一个关键的地方:

            viewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
            nav.modalPresentationStyle = UIModalPresentationOverCurrentContext;

这两句可以保证,下一个视图覆盖了当前视图的时候,当前视图依然在渲染(具体请Google)

另外,在推入下一个ViewController,我也告诉了下一个VC,他上一个视图的当前视图

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
    CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;

    SecondViewController *secondVC = [[SecondViewController alloc]init];
    secondVC.previousNav = self.navigationController;//告诉下一个视图,它的上一个视图是谁
    [self animToNextViewController:secondVC beginRect:CGRectMake(0, screenHeight/2-20, screenWidth, 40)];
}

这样设置是为了方便下一个视图dismiss的时候,依然有一个退回的动画
下面就说结束动画:

- (void)dismissSelf {

    if (self.previousNav) {
        self.previousNav.view.transform = CGAffineTransformMakeScale(0.85, 0.85);
        [UIView animateWithDuration:0.5 animations:^{
            self.previousNav.view.transform = CGAffineTransformIdentity;
        } completion:^(BOOL finished) {

        }];
        [self dismissViewControllerAnimated:YES completion:nil];
    }else{
        [self dismissViewControllerAnimated:YES completion:nil];
    }

}

结束动画很简单,如果上一个视图的属性不为空,就执行定制动画,否则就执行默认动画
如果可以显示定制动画,首先把上一个视图设置成缩小的样子,然后在动画里逐渐放大视图,知道原样大小,
这样就可以流畅完整的实现整个动画了

如果您有更好的实现,或者我这个实现哪里非常耗费性能,还请多多指出,多谢大家。

點擊查看更多內(nèi)容
2人點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
移動開發(fā)工程師
手記
粉絲
11
獲贊與收藏
446

關(guān)注作者,訂閱最新文章

閱讀免費教程

感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學(xué)

大額優(yōu)惠券免費領(lǐng)

立即參與 放棄機會
微信客服

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

幫助反饋 APP下載

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

公眾號

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

舉報

0/150
提交
取消