iOS Segue - 从左到右 - [英] iOS Segue - Left to Right -

查看:119
本文介绍了iOS Segue - 从左到右 - 的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了有关segues的其他帖子但没有解决我的问题。

I've read the other posts on segues but none solve my question.

简单地说,我的 ViewController 是订购的,就像一本书。我希望向后过渡(例如:从第9页到第8页)始终从左到右呈现(滑过)。我想要从右到左呈现前向过渡(从第9页到第10页)。

Simply put, my ViewControllers are ordered, like a book. I want backward transitions (example: from page 9 to 8) to always present (slide over) from left to right. I want forward transitions (from page 9 to 10) to present from right to left.

是的,如果您逐页翻页,我的导航控制器后退按钮(左上角)会显示如下内容。但是,如果从索引中跳转,则导航控制器上的后退功能会将您带回索引。

Yes, my nav-controller back button (top left) presents like this if you are paging through page by page. However, if you jump in from an Index then the back function on the nav controller takes you back to the index.

我的目标是,如果用户从索引跳到第9页(例如),然后向右滑动,它会向右滑动页面并显示第8页。一旦在第8页,如果他们向左轻拂,页面将向左轻弹,他们将再次在第9页。

My objective is that if a user jumps to page 9 (for example) from an index, then swipes right, it'll flick the page off to the right and show page 8. Once on page 8, if they flick left the page will get flicked off to the left and they'll be on page 9 again.

所有我的 ViewController s默认情况下是从右到左滑动显示。

All my ViewControllers are by, default, presenting by sliding in from right to left.

示例:
想想它就像一本书,如果我使用索引跳到第4章,然后向右滑动并从堆栈弹出一个视图,我将回到索引。但是,如果您正在使用第394章第4章并向右滑动,则不想返回索引!您想要转到第393页第3章的最后一页!所以导航堆栈对我没有帮助。

Example: Think of it like a book, if I use the Index to hop to chapter 4, then swipe right and pop a view from the stack, I'll be back at the Index. But if you're on Chapter 4, page 394 and you swipe right, you don't want to go back to the index! You want to go to the last page of chapter 3, page 393! So the nav stack is no help to me.

结束示例

详细信息:
1.我正在使用新的XcodeShow在按钮上点击以在ViewControllers之间切换。

Details: 1. I'm using the new Xcode "Show" on button-tap to switch between ViewControllers.


  1. 我正在使用导航控制器,顶部 - 左后退按钮功能。这使用导航堆栈并且运行正常。

  1. I'm using a navigation controller, for the top-left "Back" button functionality. This uses the nav stack and works fine.

但是我在底部有自己的自定义导航栏(后退按钮,主页按钮,索引按钮,前进按钮)和手势。这些就是我想要的书籍功能。

However I have my own custom nav-bar at the bottom (Back Button, Home Button, Index Button, Forward Button) and gestures. These are what I want to have book-like functionality with.

在swift编码。

使用Xcode 6.3

Working with Xcode 6.3

I我读过有动画代码。我已经阅读了可以使用的深度编程转换。看起来很疯狂,没有简单的方法可以选择我想要从左边显示的segue并轻松地反转动画。

I've read that there's animation code. I've read there's in depth programatic transitions that can be used. It just seems crazy that there's no simple way to just select the segues I want to present from the left and easily reverse the animation.

谢谢!

尝试日志:

I tried DCDC's code:
    UIView.transitionWithView(self.window!, duration: 0.5, options:.TransitionFlipFromLeft, animations: { () -> Void in
            self.window!.rootViewController = mainVC
            }, completion:nil)

当我将DCDC的代码插入 IBAction 时,会返回此错误我的反扫描

This error is returned when I insert DCDC's code into an IBAction for my back-swipe

推荐答案

这就是我在不需要导航控制器的情况下实现效果的方法。请尝试这样做:

This is how I achieve the effect without requiring a nav-controller. Try this instead:

Swift 4:

import UIKit
class SegueFromLeft: UIStoryboardSegue {
    override func perform() {
        let src = self.source
        let dst = self.destination

        src.view.superview?.insertSubview(dst.view, aboveSubview: src.view)
        dst.view.transform = CGAffineTransform(translationX: -src.view.frame.size.width, y: 0)

        UIView.animate(withDuration: 0.25,
                              delay: 0.0,
                            options: .curveEaseInOut,
                         animations: {
                                dst.view.transform = CGAffineTransform(translationX: 0, y: 0)
                                },
                        completion: { finished in
                                src.present(dst, animated: false, completion: nil)
                                    }
                        )
    }
}

Swift 3:

import UIKit

class SegueFromLeft: UIStoryboardSegue
{
    override func perform()
    {
        let src = self.sourceViewController
        let dst = self.destinationViewController

        src.view.superview?.insertSubview(dst.view, aboveSubview: src.view)
        dst.view.transform = CGAffineTransformMakeTranslation(-src.view.frame.size.width, 0)

        UIView.animateWithDuration(0.25,
            delay: 0.0,
            options: UIViewAnimationOptions.CurveEaseInOut,
            animations: {
                dst.view.transform = CGAffineTransformMakeTranslation(0, 0)
            },
            completion: { finished in
                src.presentViewController(dst, animated: false, completion: nil)
            }
        )
    }
}

然后在故事板中单击在segue你想改变。在属性检查器中,将类型更改为自定义并将类更改为SegueFromLeft

Then in the storyboard, click on the segue you'd like to change. In the attributes inspector change the type to 'Custom' and change the class to 'SegueFromLeft'

这篇关于iOS Segue - 从左到右 - 的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆