UINavigationControllerのアニメーションをカスタマイズしたい(未解決)
UINavigationControllerのアニメーションをカスタマイズしたいなと思って、ググってたらこんな情報があった。
iphone - UINavigationController Custom Transition Animations - Stack Overflow
Core Animationを使ってアニメーションさせて、アニメーションが終わったらアニメーションOFFでpushViewControllerする、という方法。
これでうまくいくかと思ったけど、この方法だとアニメーション中は片方のビューコントローラのビューしか表示されない。標準のアニメーションみたいにアニメーション中も両方のビューを表示したい。
なのでこんな方法を考えた。
// ビューをねじこむ [self.navigationController.view addSubview:nextViewController.view]; // Get position of old view controller CGPoint center = [oldViewController.view center]; // Position new view controller to the right of old one [newViewController.view setCenter:CGPointMake(center.x + 320, center.y)]; // Animate change [UIView beginAnimations:@"myAnimation" context:NULL]; // Move old view off screen [oldViewController.view setCenter:CGPointMake(center.x - 320, center.y)]; // Move new view onto screen [newViewController.view setCenter:center]; // Set animation delegate to self so that we can detect when animation is complete [UIView setAnimationDelegate:self]; [UIView setAnimationDidStopSelector:@selector(animationComplete:finished:target:)]; // Finish animation block [UIView commitAnimations];
あらかじめaddSubviewしとけば表示されるんじゃないの、と。
なんとなく望む結果になったけど、ナビゲーションバーの表示にかぶったり座標がなんかずれたりよくわからない。
もう自分で一から画面遷移のコード書いた方が早い気がしてきた...。