亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

這些切換都要放在NavigationController里做管理,怎么實現,求個思路

這些切換都要放在NavigationController里做管理,怎么實現,求個思路

iOS
拉丁的傳說 2023-04-16 22:18:48
默認的UINavigationController push和pop的默認動畫都是左右滑動推出,我的應用要求這種界面切換的動畫效果復雜一點,大概有這么幾個:更快的左右推出,默認是0.3秒,我需要快一倍帶抖動的左右推出水平翻轉紙張翻頁效果
查看完整描述

3 回答

?
慕哥6287543

TA貢獻1831條經驗 獲得超10個贊

1. 如果樓主想要使用UINavigationController中的view controller stack,并且還想要同時自定義push、pop的動畫效果,基本上是不可能的。原因在于想要使用view controller stack,就無法躲開
pushViewController:animated:這個方法,而一旦使用pushViewController:animated:,UINavigationController就會強制將要推入的viewController的frame設為當前可視區域的frame,從而斷絕一切想要自定義動畫的后路,例如如下代碼,是不會產生任何效果的:

UINavigationController+CustomAnimation.h

@interface UINavigationController (CustomAnimation)- (void)customPushViewController:(UIViewController *)viewController;@end

UINavigationController+CustomAnimation.m

#import "UINavigationController+CustomAnimation.h"- (void)customPushViewController:(UIViewController *)viewController
{
    viewController.view.frame = (CGRect){0, -viewController.view.frame.size.height, viewController.view.frame.size};
    [self pushViewController:viewController animated:NO];
    [UIView animateWithDuration:.15f
                     animations:^{
                         viewController.view.frame = (CGRect){0, 0, self.view.bounds.size};
                     }];
}

2. 如果僅僅是想添加自定義的push、pop動畫,而不使用view controller stack,那么,如下代碼就可以實現一個從上到下的push效果:

UINavigationController+CustomAnimation.h文件同上。

UINavigationController+CustomAnimation.m

#import "UINavigationController+CustomAnimation.h"- (void)customPushViewController:(UIViewController *)viewController
{
    viewController.view.frame = (CGRect){0, -viewController.view.frame.size.height, viewController.view.frame.size};
    [self.topViewController.view addSubview:viewController.view];
    [UIView animateWithDuration:.15f
                     animations:^{
                         viewController.view.frame = (CGRect){0, 0, self.view.bounds.size};
                     }];
}


查看完整回答
反對 回復 2023-04-20
?
湖上湖

TA貢獻2003條經驗 獲得超2個贊

雖然基于navctrl,但是你可以不用navctrl push的方法,可以用viewctrl的presentModalViewController。至于速度的話,這些系統的默認都是0.3s,動畫方式也就是系統默認的幾個。

查看完整回答
反對 回復 2023-04-20
?
月關寶盒

TA貢獻1772條經驗 獲得超5個贊

CATransition* transition = [CATransition animation];

transition.type = kCATransitionPush;//可更改為其他方式

transition.subtype = kCATransitionFromLeft;//可更改為其他方式

transition.duration=0.15;

[self.navigationController.view.layer addAnimation:transition forKey:kCATransition];

[self.navigationController pushViewController:viewController animated:YES];


查看完整回答
反對 回復 2023-04-20
  • 3 回答
  • 0 關注
  • 189 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號