首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将幻灯片过渡动画的方向更改为左侧

将幻灯片过渡动画的方向更改为左侧
EN

Stack Overflow用户
提问于 2013-02-19 20:49:17
回答 2查看 2.1K关注 0票数 1

当我打开一个特定的视图时,我想将幻灯片动画的方向从右到左更改为-->,而不是默认的方向(从左到右)。

我找到了一个解决方案来改变动画过渡。虽然这是一个翻转动画,并且我想更改导航控制器的默认幻灯片动画的方向。

代码语言:javascript
复制
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#

EN

回答 2

Stack Overflow用户

发布于 2013-02-19 23:52:00

抱歉,我在MonoTouch/C#中什么也没有得到,但我在ObjC中实现了同样的行为,它完美地模拟了滑动。在这种情况下,它用于模拟使用选项卡栏访问视图时的向后滑动行为。也许它是有帮助的:

代码语言:javascript
复制
- (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#中:

代码语言:javascript
复制
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;
         });
}
票数 2
EN

Stack Overflow用户

发布于 2016-05-13 10:30:42

下面就是你想要的。这是从选项卡视图转换而来的。希望它能帮助一些人:

代码语言:javascript
复制
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;
            }
        );
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14957927

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档