0
私はwebviewとUIToolbarを持つビューを持っています。1つのUIViewを削除して別のUIViewを追加してスライドアニメーションを作成します
"kCATransitionFromTop"トランジションを実行するアニメーションを作成するには、最初に以前のwebviewを削除してから、新しいwebViewをスーパービューに追加します。 この移行中に、ツールバーを現在の位置にして移動しないようにします。
コード: ツールバーを追加
toolbar = [[UIToolbar alloc] init];
toolbar.barStyle = UIBarStyleDefault;
toolbar.tintColor = [UIColor blackColor];
[toolbar setFrame:CGRectMake(0, 480 - 88 - 20, 320.0, 44)];
//Add the toolbar as a subview to the navigation controller.
[self.view addSubview:toolbar];
アニメーション:
UIView *currentView = webView;
UIView *theWindow = [currentView superview];
UIView *newView = [[UIWebView alloc] initWithFrame: CGRectMake(0, 0, 320, self.view.bounds.size.height - self.navigationController.toolbar.frame.size.height)];
newView.backgroundColor = [UIColor whiteColor];
// remove the current view and replace with new view
[currentView removeFromSuperview];
[theWindow insertSubview:newView belowSubview:toolbar];
// set up the animation
CATransition *animation = [CATransition animation];
[animation setDuration:0.4];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromTop];
[animation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[[theWindow layer] addAnimation:animation forKey:@"PushNextArticleView"];
すべては私がやったこと ...ツールバーは、同様のWebViewで動いている以外は、[OK]を動作するように思えます間違っていて、どうやってこの問題を解決できますか?
ありがとうございました。しかし、トランジションの間にブラックホールがあります。 removeFromSuperviewはアニメーション化されていないと思いますか? – user959974
修正。レイヤーのデリゲートとして自分自身を設定し、 '-animationDidStop:finished:'を実装します。アニメーションが停止したときにメッセージが表示され、元のビューがスーパービューから削除されます。 –
私は[currentView removeFromSuperview]をコメントアウトします。 、どういうわけかビューはアニメーションの実行を拒否します。それは、彼らがinsertSubviewメソッドではないようです。私はAddSubviewにそれを伝えれば、アニメーションはうまくいくでしょう..... – user959974