2013-02-19 85 views
1

當我打開特定視圖,我想改變幻燈片的動畫的方向 - 從右>到左,而不是默認的方向(從左到右)。改變方向向左

我找到了一個解決方案來改變動畫過渡。雖然這是一個翻轉動畫,但我想要更改導航控制器的默認滑動動畫的方向。

var screen = new Screen(); 
NavigationController.PushViewController(screen, false); 

UIView.BeginAnimations(null,IntPtr.Zero); 
UIView.SetAnimationDuration(0.75); 
UIView.SetAnimationTransition(UIViewAnimationTransition.FlipFromLeft , NavigationController.View,true); // <-- Change the animation 
UIView.CommitAnimations(); 

注:我使用的MonoTouch/C#

回答

1

對不起,我又沒有什麼在MonoTouch中/ C#,但我已經實現在ObjC相同的行爲,它完美地模擬了滑動。在這種情況下,它用於在使用TabBar進入視圖時模擬回退行爲。也許是有幫助的:

- (void)hitBack 
{ 
    // Get the views. 
    UIView * fromView = self.tabBarController.selectedViewController.view; 
    UIView * toView = ((UIViewController *)[self.tabBarController.viewControllers objectAtIndex:0]).view; 

    // Get the size of the view area. 
    CGRect viewSize = fromView.frame; 

    // Add the to view to the tab bar view. 
    [fromView.superview addSubview:toView]; 

    // Position it off screen. 
    toView.frame = CGRectMake(-320 , viewSize.origin.y, 320, viewSize.size.height); 

    [UIView animateWithDuration:0.4 animations: 
    ^{ 
     // Animate the views on and off the screen. This will appear to slide. 
     fromView.frame =CGRectMake(320 , viewSize.origin.y, 320, viewSize.size.height); 
     toView.frame =CGRectMake(0, viewSize.origin.y, 320, viewSize.size.height); 
    } 
        completion:^(BOOL finished) 
    { 
     if (finished) 
     { 
      // Remove the old view from the tabbar view. 
      [fromView removeFromSuperview]; 

      //change tab 
      self.tabBarController.selectedIndex = 0; 
     } 
    }]; 
} 

在C#:

void HitBack() 
{ 
    // Get the views. 
    var fromView = tabBarController.SelectedViewController.View; 
    var toView = tabBarController.ViewControllers [0].View; 

    // Get the size of the view area. 
    var viewSize = fromView.Frame; 

    // Add the to view to the tab bar view. 
    fromView.Superview.AddSubview (toView); 

    // Position it off screen. 
    toView.Frame = new RectangleF (-320 , viewSize.Y, 320, viewSize.Height); 

    UIView.Animate (0.4,() => { animateWithDuration:0.4 animations: 
     // Animate the views on and off the screen. This will appear to slide. 
     fromView.Frame = new RectangleF (320 , viewSize.Y, 320, viewSize.Height); 
     toView.Frame =new RectangleF (0, viewSize.Y, 320, viewSize.Height); 
    }, (bool finished) => { 
     if (finished){ 
      // Remove the old view from the tabbar view. 
      fromView.RemoveFromSuperview(); 

      //change tab 
      tabBarController.SelectedIndex = 0; 
     }); 
} 
1

這是你下面要什麼。這是從選項卡視圖轉換而來的。希望這將幫助一些人:

protected void HandleLeftSwipe(UISwipeGestureRecognizer recognizer) 
{ 
    if (this.TabBarController.SelectedIndex != 4) { 
     UIView fromView = this.TabBarController.SelectedViewController.View; 
     UIView toView = this.TabBarController.ViewControllers[this.TabBarController.SelectedIndex+1].View; 

     // Get the size of the view area. 
     var viewSize = fromView.Frame; 

     // Add the to view to the tab bar view. 
     fromView.Superview.AddSubview (toView); 

     var minAlpha = -320.0; 
     var maxAlpha = 320.0; 
     var midAlpha =0.0; 
     // Position it off screen. 
     toView.Frame = new CGRect (maxAlpha , viewSize.Y, maxAlpha, viewSize.Height); 
     UIView.Animate (.3,.1, UIViewAnimationOptions.CurveEaseOut , 
      () => { 
       fromView.Frame = new CGRect (minAlpha , viewSize.Y, maxAlpha, viewSize.Height); 
       toView.Frame =new CGRect (midAlpha, viewSize.Y, maxAlpha, viewSize.Height); 
      }, 
      () => { 
       fromView.RemoveFromSuperview(); 
       this.TabBarController.SelectedIndex = this.TabBarController.SelectedIndex + 1; 
      } 
     ); 
    } 
} 

protected void HandleRightSwipe(UISwipeGestureRecognizer recognizer) 
{ 
    if (this.TabBarController.SelectedIndex != 0) { 
     UIView fromView = this.TabBarController.SelectedViewController.View; 
     UIView toView = this.TabBarController.ViewControllers[this.TabBarController.SelectedIndex-1].View; 

     // Get the size of the view area. 
     var viewSize = fromView.Frame; 

     // Add the to view to the tab bar view. 
     fromView.Superview.AddSubview (toView); 

     var minAlpha = -320.0; 
     var maxAlpha = 320.0; 
     var midAlpha =0.0; 
     // Position it off screen. 
     toView.Frame = new CGRect (minAlpha , viewSize.Y, maxAlpha, viewSize.Height); 
     UIView.Animate (.3,.1, UIViewAnimationOptions.CurveEaseOut , 
      () => { 
       fromView.Frame = new CGRect (maxAlpha , viewSize.Y, maxAlpha, viewSize.Height); 
       toView.Frame =new CGRect (midAlpha, viewSize.Y, maxAlpha, viewSize.Height); 
      }, 
      () => { 
       fromView.RemoveFromSuperview(); 
       this.TabBarController.SelectedIndex = this.TabBarController.SelectedIndex - 1; 
      } 
     ); 
    } 
}