[英]IOS Transition between child viewControllers on same screen
I am trying to get the new IOS 5 Container viewControllers working properly but I am having an issue animating between them. 我正在尝试使新的IOS 5容器viewControllers正常工作,但是它们之间存在动画问题。
I have a "rootViewController". 我有一个“ rootViewController”。 In this controller, I have added 2 child view controllers.
在此控制器中,我添加了2个子视图控制器。 This functions almost like a splitViewController.
该功能几乎类似于splitViewController。 On the left I have a VC that handles navigation, and on the right I have a VC that shows specific content.
左侧有一个用于处理导航的VC,而右侧有一个用于显示特定内容的VC。
I am trying to animate between the VC on the right, and a new VC which will replace it. 我正在尝试在右侧的VC和将替换它的新VC之间创建动画。
This is my code for the animation: 这是我的动画代码:
public void Animate(UIViewController toController) {
AddChildViewController(toController);
activeRightController.WillMoveToParentViewController(null);
toController.View.Frame = activeRightController.View.Frame;
Transition(activeRightController, toController, 1.0, UIViewAnimationOptions.TransitionCurlUp, () => {},
(finished) => {
activeRightController.RemoveFromParentViewController();
toController.DidMoveToParentViewController(this);
activeRightController = toController;
});
activeRightController = toController;
}
Almost everything works, it transitions to my new view using the CurlUp transition, however the transition itself goes across the WHOLE screen...not just the single view that I want to transition. 几乎所有东西都可以使用,它使用CurlUp过渡过渡到我的新视图,但是过渡本身遍及整个屏幕...而不仅仅是我要过渡的单个视图。 Its "curling Up" the parent view, and not the child.
它“卷曲”了父视图,而不是子视图。 It does however replace only the child view underneath it.
但是,它仅替换其下面的子视图。 I hope this makes sense.
我希望这是有道理的。
I created a new UIViewController class that is a thin container for the right side controllers and handles the swap animation. 我创建了一个新的UIViewController类,该类是用于右侧控制器的瘦容器并处理交换动画。 See the sample below.
请参阅下面的示例。
using System;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using System.Drawing;
namespace delete20120425
{
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
UIWindow window;
MainViewController mvc;
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
window = new UIWindow (UIScreen.MainScreen.Bounds);
mvc = new MainViewController ();
window.RootViewController = mvc;
window.MakeKeyAndVisible ();
return true;
}
}
public class MainViewController : UIViewController
{
SubViewController vc1;
ContainerViewController vc2;
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
vc1 = new SubViewController (UIColor.Blue);
this.AddChildViewController (vc1);
this.View.AddSubview (vc1.View);
UIButton btn = UIButton.FromType (UIButtonType.RoundedRect);
btn.Frame = new RectangleF (20, 20, 80, 25);
btn.SetTitle ("Click", UIControlState.Normal);
vc1.View.AddSubview (btn);
SubViewController tmpvc = new SubViewController (UIColor.Yellow);
vc2 = new ContainerViewController (tmpvc);
this.AddChildViewController (vc2);
this.View.AddSubview (vc2.View);
btn.TouchUpInside += HandleBtnTouchUpInside;
}
void HandleBtnTouchUpInside (object sender, EventArgs e)
{
SubViewController toController = new SubViewController (UIColor.Green);
vc2.SwapViewController (toController);
}
public override void ViewWillLayoutSubviews ()
{
base.ViewDidLayoutSubviews ();
RectangleF lRect = this.View.Bounds;
RectangleF rRect = lRect;
lRect.X = lRect.Y = lRect.Y = 0;
lRect.Width = .3f * lRect.Width;
rRect.X = lRect.Width + 1;
rRect.Width = (.7f * rRect.Width)-1;
this.View.Subviews[0].Frame = lRect;
this.View.Subviews[1].Frame = rRect;
}
public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
return true;
}
}
public class ContainerViewController : UIViewController
{
UIViewController _ctrl;
public ContainerViewController (UIViewController ctrl)
{
_ctrl = ctrl;
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
AddChildViewController (_ctrl);
View.AddSubview (_ctrl.View);
}
public void SwapViewController (UIViewController toController)
{
UIViewController activeRightController = _ctrl;
AddChildViewController(toController);
activeRightController.WillMoveToParentViewController(null);
toController.View.Frame = activeRightController.View.Frame;
Transition(activeRightController, toController, 1.0, UIViewAnimationOptions.TransitionCurlUp, () => {},
(finished) => {
activeRightController.RemoveFromParentViewController();
toController.DidMoveToParentViewController(this);
activeRightController = toController;
});
activeRightController = toController;
}
public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
return true;
}
public override void ViewWillLayoutSubviews ()
{
base.ViewWillLayoutSubviews ();
RectangleF tmp = this.View.Frame;
tmp.X = tmp.Y = 0;
_ctrl.View.Frame = tmp;
}
}
public class SubViewController : UIViewController
{
UIColor _back;
public SubViewController (UIColor back)
{
_back = back;
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
this.View.BackgroundColor = _back;
}
public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
return true;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.