改变方向向左
问题描述:
当我打开特定视图,我想改变幻灯片的动画的方向 - 从右>到左,而不是默认的方向(从左到右)。改变方向向左
我找到了一个解决方案来改变动画过渡。虽然这是一个翻转动画,但我想要更改导航控制器的默认滑动动画的方向。
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#
答
对不起,我又没有什么在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;
});
}
答
这是你下面要什么。这是从选项卡视图转换而来的。希望这将帮助一些人:
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;
}
);
}
}