切换到另一个视图,但留在导航控制器

问题描述:

我有一个关于特定产品的详细信息的导航控制器,其中一个细节是产品的小图像。现在我想添加一个按钮,该按钮必须通过产品的放大图像转到视图控制器。切换到另一个视图,但留在导航控制器

如何使放大后的图像与细节屏幕位于同一导航控制器上,并且屏幕翻转过渡,但标题栏和标签栏不会翻转。

在导航控制器上添加了两个视图的概览图。

enter image description here

您可以使用类似:

UIView.Transition(this.NavigationController.View, 1f, 
UIViewAnimationOptions.CurveEaseInOut | UIViewAnimationOptions.TransitionFlipFromRight, 
delegate { this.NavigationController.PushViewController(this.ImageViewController, false); }); 

要使图片视图翻转的navogation控制器上时得到推而不是默认的过渡。 ImageViewController的title属性应该与您的详细信息中的属性相同。

UINavigationController的想法是处理多个控制器,因此您不应该通过覆盖视图来解决它。

+0

你一定是在开玩笑。你击败了我30秒。 :) – holmes

+0

我开始的方式提前但忘记完成答案,所以你被击败了至少15分钟,队友! :-) – Krumelur

+0

我用你的转换代码,它与霍姆斯的解决方案一起工作,但在翻转过渡中,我有一个短时间的黑屏,翻转视图的背面也是黑色的,而不是视图去哪里。这是默认行为吗? – Renzzs

将两个视图添加到控制器并为其帧属性设置动画以获得所需的效果。
请参阅下面的示例。

using System; 
using System.Collections.Generic; 
using System.Linq; 

using MonoTouch.Foundation; 
using MonoTouch.UIKit; 
using System.Drawing; 

namespace delete20121203 
{ 
    // The UIApplicationDelegate for the application. This class is responsible for launching the 
    // User Interface of the application, as well as listening (and optionally responding) to 
    // application events from iOS. 
    [Register ("AppDelegate")] 
    public partial class AppDelegate : UIApplicationDelegate 
    { 
     // class-level declarations 
     UIWindow window; 

     // 
     // This method is invoked when the application has loaded and is ready to run. In this 
     // method you should instantiate the window, load the UI into it and then make the window 
     // visible. 
     // 
     // You have 17 seconds to return from this method, or iOS will terminate your application. 
     // 
     public override bool FinishedLaunching (UIApplication app, NSDictionary options) 
     { 
      // create a new window instance based on the screen size 
      window = new UIWindow (UIScreen.MainScreen.Bounds); 

      var ctrl = new MyViewController(); 
      var nav = new UINavigationController (ctrl); 

      window.RootViewController = nav; 


      // make the window visible 
      window.MakeKeyAndVisible(); 

      return true; 
     } 
    } 

    public class MyViewController : UIViewController 
    { 
     UIButton _button1; 
     UIButton _button2; 
     UIView _view1; 
     UIView _view2; 

     public override void ViewDidLoad() 
     { 
      base.ViewDidLoad(); 
      Title = "Test"; 

      _view1 = new UIView (View.Bounds); 
      _view1.AutoresizingMask = UIViewAutoresizing.All; 
      _view1.BackgroundColor = UIColor.White; 

      _button1 = UIButton.FromType (UIButtonType.RoundedRect); 
      _button1.Frame = new System.Drawing.RectangleF (10, 10, 150, 44); 
      _button1.SetTitle ("Click", UIControlState.Normal); 
      _button1.TouchUpInside += Button1Click; 

      _view2 = new UIView (View.Bounds); 
      _view2.AutoresizingMask = UIViewAutoresizing.All; 
      _view2.BackgroundColor = UIColor.LightGray; 
      RectangleF hideRect = _view2.Frame; 
      hideRect.X = hideRect.X + hideRect.Width; 
      _view2.Frame = hideRect; 

      _button2 = UIButton.FromType (UIButtonType.RoundedRect); 
      _button2.Frame = new System.Drawing.RectangleF (10, 10, 150, 44); 
      _button2.SetTitle ("Back", UIControlState.Normal); 
      _button2.TouchUpInside += Button2Click; 

      _view1.Add (_button1); 
      _view2.Add (_button2); 

      View.Add (_view1); 
      View.Add (_view2); 
     } 

     void Button1Click (object sender, EventArgs e) 
     { 
      UIView.Animate (.5f, 0, UIViewAnimationOptions.CurveEaseInOut, delegate { 
       _view2.Frame = View.Frame; 

       RectangleF hideRect = _view1.Frame; 
       hideRect.X = hideRect.X - hideRect.Width; 
       _view1.Frame = hideRect; 
      }, 
      null); 
     } 

     void Button2Click (object sender, EventArgs e) 
     { 
      UIView.Animate (.5f, 0, UIViewAnimationOptions.CurveEaseInOut, delegate { 
       RectangleF hideRect = _view2.Frame; 
       hideRect.X = hideRect.X + hideRect.Width; 
       _view2.Frame = hideRect; 

       _view1.Frame = View.Frame; 
      }, 
      null); 
     } 
    } 
} 
+0

如果我将你的解决方案与Krumelur的代码结合起来,我会得到一个翻转过渡(如果我复制和粘贴你的解决方案,我不会得到翻转动画,只是幻灯片动画)。但是我正在使用Storyboard,所以我不必一直编程用户界面。现在是具有图像和一个按钮的视图对编码视图不是一个大问题。有关如何与故事板做到这一点的任何提示? – Renzzs

+0

据我所知,使用故事板只会帮助您完成初始布局。我在ViewDidLoad中的所有代码都可以在XCode编辑器中实现。您将不得不为Button1Click和Button2Click创建操作。您还必须为_view1和_view2添加插座。 – holmes