- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 this提供类似 Tinder (Swift 3) 导航栏的框架。
我的目标是以一种透明的方式使用它——也就是说——将它嵌入并在 Storyboard上拥有 3 个独立的 View Controller ,以及它们的 VC.swift 文件并使用 segues。
Here是一个工作测试项目,具有 Tinder 风格和 Storyboard 中的 3 个 ViewController。
在我的项目中使用它之前,我想测试它,所以我更新了这个项目。
如我所见,nav 是具有 3 个 VC 并在它们之间切换的 UINavigationController。我想在 Storyboard上看到他。
所以代替了:
var nav: UINavigationController?
我在 UI 构建器和 UINavigationController 类上创建了一个 UINavigationController,名为 MainNavigationController。
var nav: MainNavigationController?
nav = mainStb.instantiateViewController(withIdentifier: "mainNavigationController") as? MainNavigationController
我还向 Storyboard添加了一个简单的初始 View Controller ,从这个 VC 我将(使用按钮)连接到 MainNavigationController:
@IBAction func buttonSegue(_ sender: Any) {
setNav()
self.performSegue(withIdentifier: "segue", sender: nil)
}
func setNav() {
//// implement my logic (if logged in go to... if not go to...)
instantiateControllers()
setItems()
let items = [UIImageView(image: chat),
UIImageView(image: gear),
UIImageView(image: profile)]
let controllers = [oneVC!,
twoVC!,
threeVC!] as [UIViewController]
controller = SLPagingViewSwift(items: items, controllers: controllers, showPageControl: false)
setupController()
nav = MainNavigationController(rootViewController: controller)
appDelegate.window?.rootViewController = nav
appDelegate.window?.makeKeyAndVisible()
}
到目前为止一切正常。 但是:
我目前唯一的问题是我无法控制转场。在我添加的 3 个 View Controller 中
override func prepare(for segue: UIStoryboardSegue, sender: Any?)
但它永远不会命中此方法。我需要它在 View Controller 之间传递数据。怎么做到的?
此外,您将如何通过点击一个元素(如按钮)实现从一个 View Controller 到另一个 View Controller 的转场?如果我使用按钮设置常规转场,从一个 VC 到另一个 - 它显示没有导航栏的目标 VC
我上传了我当前的实现 here .
任何帮助将不胜感激。谢谢。
最佳答案
好的。我已经下载了你的项目,因为你的解释并不是很有帮助..
首先:如果您的 Storyboard只有空白屏幕,请为它们着色,以便其他编码人员能够更快地了解发生了什么。
您从黄色 VC
到 UINavigationController
的 segue 被触发,但未被使用,因为您以编程方式实例化了 UINavigationController
。
// Sets the root
func setNav() {
// here
nav = MainNavigationController(rootViewController: controller)
appDelegate.window?.rootViewController = nav
appDelegate.window?.makeKeyAndVisible()
}
您从绿色 VC 到蓝色 VC 的转场没有任何意义,因为没有转场。这些 Controller 嵌入到同一个 Controller 中。您正在设置 perform(forSegue
函数,但您永远不会调用它。如果有 segue,您只会使用 perform(forSegue
。但事实并非如此。
不使用 setNav()
函数设置按钮:
@IBAction func buttonSegue(_ sender: Any) {
//setNav()
self.performSegue(withIdentifier: "segue", sender: nil)
}
将蓝色 VC
作为单个 VC
生成。
没有 segue 的相同函数,结果与有 segue 的逻辑相同。因为如前所述,您无论如何都以编程方式设置所有内容:
@IBAction func buttonSegue(_ sender: Any) {
setNav()
//self.performSegue(withIdentifier: "segue", sender: nil)
}
由于您已经在全局实例化了 VC
,因此您可以在全局范围内获取/设置 VC
值...
class OneVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func passData(_ sender: Any) {
let oneVCString = "This String is passed from OneVC"
twoVC?.theLabel.text = oneVCString
}
}
结果:
Here is this on Github作为你项目的一个分支。我还从 AppDelegate
中删除了您的代码。没有用,无论如何都被调用了。您已经在 Interface Builder 中做了同样的事情。
最后但同样重要的是我的评论:清理你的代码!其他用户可能对此有不同的看法,但这不是我想与其他编码人员一起工作的方式:
import UIKit
class TwoVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
print("from two to...")
print(segue.identifier!)
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}
删除所有不必要的评论。
关于ios - swift 中类似 Tinder 的导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40350010/
我有一个带有 cardview 的应用程序,就像 tinder 一样。现在我想用 AdMob 添加广告。AdMob 提供 4 种广告格式: 横幅 插页式(整页广告) 奖励(视频) 母语 我想在我的应用
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 5 年前。
我通过“zero2launch”购买了有关如何制作 Tinder 应用程序的 udemy 教程,并按照它进行操作,效果非常好,但是,卡片上的用户是男性和女性,我想找到一种方法 - 使用分段控制 - 仅
我正在尝试制作类似 tinder 的可刷卡。我有这个图书馆 https://github.com/kikoso/Swipeable-Cards .我按照演示操作,效果很好。然而,该演示只有一个 car
我正在组装一个自动向右滑动的 python Tinder 机器人,我还希望它能够发送消息。一切正常,除了匹配时应该发送消息,但实际上却没有。我已经尝试了我能想到的所有可能的代码组合,但无济于事。我和我
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 5 年前。 Improve
我正在开发一个 iOS 应用程序(使用 Objective-C)。 我正在使用 MDCSwipeToChoose API 滑动 View (喜欢和不喜欢)。 我想在应用程序中再添加一个按钮(像 las
所以我注意到,像 Tinder 这样的应用程序可以在其他人的手机上显示用户 A 的 Instagram 连接,即使不需要其他用户实际登录 instagram。 例如:用户 A 连接 instagram
我正在寻找一种方法来实现与在 Tinder 应用程序中的选项卡之间滑动时相同的过渡效果。- 颜色过渡。- 图像过渡。 如下图所示: 如果有人已经知道如何做到这一点,我会加入。如果没有,我将在这里分享我
我有一个应用程序,我可以根据他们的位置、上次事件和许多其他过滤器搜索用户,现在已经达到了性能不够好但由于用户数量增加而必须改进的地步。但是,我不确定最好的前进方式是什么,如果有任何意见,我将不胜感激!
我正在尝试使用 this提供类似 Tinder (Swift 3) 导航栏的框架。 我的目标是以一种透明的方式使用它——也就是说——将它嵌入并在 Storyboard上拥有 3 个独立的 View C
对于 iOS 中的 Tinder 应用程序,我假设他们在 ImageView 上使用平移手势识别器。在用户开始移动的图像下方如何显示另一个图像?他们是否有另一个 ImageView ,在手势识别器完成
谁能告诉我 smack、tinder 和 whack 之间的区别是什么? Tinder 和 whack 是 smack 的瘦身版吗?这三个图书馆有不同的用途吗? 最佳答案 Smack 是一个客户端库。
我想在 flutter 中创建可滑动的类似 tinder 的卡片,它可以在向左或向右滑动时调用某些功能,但在 Flutter 中这样做似乎太复杂了。现在我已经使用带有 Dismissible 的 Li
试图测试与我的 ws 的连接,但服务器看不到任何连接。 我想我错过了什么,你能告诉我我错过了什么吗? 日志: D/Connection$connect:应该连接 D/Connection$connec
我想在 flutter 中创建可滑动的类似 tinder 的卡片,它可以在向左或向右滑动时调用某些功能,但在 Flutter 中这样做似乎太复杂了。现在我已经使用带有 Dismissible 的 Li
理论上说我们有一个名为 matches 的表(带有一些测试数据): create table matches ( user_id int, target_id int ); INSERT IN
我已经开始开发一个 Android 应用程序,我需要在其中进行基于距离的搜索。用户应该能够选择最大距离,比方说 3 公里。我已经编写了一些代码,用于获取每个用户的当前位置(纬度、经度)并将其存储在 m
我目前正在开发一款类似 Tinder 的应用程序,它可以从网络服务中检索一些数据。 我已经编写了我的函数来检索数据,这就像一个魅力,并且我还实现了卡片模型。 问题是,我不知道如何编码事实以将解码 js
所以,我有一个 ViewPager,我想实现一个简单的 Page-Indicator,就像 Tinder 处理它的图片一样: 我以为找到图书馆很容易,但我这辈子都找不到。 我不在乎条形是通过操纵点的宽
我是一名优秀的程序员,十分优秀!