簡體   English   中英

使用 uitabbarcontroller 動畫視圖更改

[英]animating view change with uitabbarcontroller

我想為我的視圖更改設置動畫,但是我不確定將我的 animation 放在哪里,因為我有一個 UITabBarController 控制我在哪個視圖上以及我也可以切換什么。這是在我的 appdelegate.m 文件中聲明的xcode 模板。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
    UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}

或者它們是每個視圖控制器中加載所有內容的區域......我認為在這里初始化 animation 可能會更好。

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title = NSLocalizedString(@"Super", @"Super");
        self.tabBarItem.image = [UIImage imageNamed:@"SuperIcon"];
    }
    return self;
}

因為我沒有做很多 animation 的視圖,然后我才可以在哪里聲明這段代碼,希望在觸摸 UITabBarButton 時動畫我的視圖變化......

[UIView transitionWithView:containerView
           duration:0.2
           options:UIViewAnimationOptionTransitionFlipFromLeft
           animations:^{ [fromView removeFromSuperview]; [containerView addSubview:toView]; 
           completion:NULL];

還是我完全錯過了船,我應該在其他地方做這件事嗎?

在 viewWillAppear 方法中嘗試以下代碼

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.4];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
                       forView:self.view cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView commitAnimations];

這對我來說適用於基於 tabBar controller 的應用程序。

在 viewWillAppear 方法的代碼中嘗試 animation

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM