当我打开特定视图时,我想将幻灯片动画的方向更改为 - >从右到左而不是默认方向(从左到右)。
我找到了一个改变动画过渡的解决方案。虽然这是一个翻转动画,但我想改变导航控制器默认幻灯片动画的方向。
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#
答案 0 :(得分: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 :(得分: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;
}
);
}
}