- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在 xib 中调用 touchedEnded 函数时呈现 ViewController,但我不知道如何实现它。
这是我项目的一部分。
//ViewController.swift
class ViewController: UIViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// add custom xib view (day view)
let view = Bundle.main.loadNibNamed("ScheduleView", owner: self, options: nil)?.first as! ScheduleView
view.frame = self.view.frame
self.view.addSubview(view)
}
}
//ScheduleView.swift
class ScheduleView.swift: UIView {
/*
// Only override draw() if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func draw(_ rect: CGRect) {
// Drawing code
}
*/
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
print("touchesBegan")
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesEnded(touches, with: event)
print("touchesEnd")
// move scene in here
// show secondViewController
}
}
//secondeViewController.swift
class secondeViewController.swift: UIViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
}
最佳答案
只有 View Controller 可以呈现另一个 View Controller 。您可以使用委托(delegate)模式来做到这一点。
创建新协议(protocol)
protocol PresentVCDelegate {
func presentVC()
}
在 ScheduleView 中添加一个属性
var presentVCDelegate: PresentVCDelegate
在您的 ViewController 中,遵守此协议(protocol)并将 View 的委托(delegate)设置为 self
//in view will appear
view.presentVCDelegate = self
不要忘记遵守协议(protocol)
extension ViewController: PresentVCDelegate {
func presentVC() {
//present your secondViewController here
}
}
最后在 ScheduleView 的 touchEnd 方法中,调用委托(delegate)方法
self.presentVCDelegate.presentVC()
关于iOS swift,在UIView中调用touchesEnded时,storyboard中的presencetViewController其他xib或ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47077546/
在我的应用程序中,我有一个 UIView 并排有两个 UITableView。位于这些之上的是一个 UIView(全部在 Storyboard中完成)。 它被设置为通过附加到顶部 UIView、DnD
我在我的 UIView 中实现了以下事件处理程序: - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]
当玩家按住按钮四处移动然后按下射击按钮时,会调用 TouchesEnded,然后取消玩家的移动。这两个操作单独工作,但当它们同时被调用时则不会。 override func touchesBegan(
我正在我的 iOS 应用程序中实现 touchesBegan 和 touchesEnded,试图检测用户何时将手指放在屏幕上以及何时松开。 我遇到的问题是,一旦 touchesBegan 被调用,如果
我正在尝试让 touchesEnded 在一个手势后触发。我包含了一个代码片段,其中可以触发 touchesBegan 和 touchesEnded。我用下面的代码得到了两个奇怪的行为。当我平移时,它
很抱歉让我感到尴尬,但请问我能否获得有关如何执行此操作的完整代码: 我希望在我的游戏中每发射一颗子弹后延迟 1 秒,以防止子弹垃圾邮件。如果可能的话,不要像我在 touchesEnded 中那样为子弹
当我调用 touchesBegan() 时 override func touchesBegan(touches: Set, withEvent event: UIEvent?) {
我有一个子类 UIView 的自定义 View 。它有一个 touchesEnded 事件,但是它没有显示在 Interface Builder 中(在事件下)。我想知道如何将该方法放入我的 View
如果我用两根手指点击屏幕太快,touchesBegan被调用,但 touchesEnded不要求其中之一。 我疯狂地用谷歌搜索,这似乎是人们至少从 2010 年以来一直存在的一个严重问题。显然它还没有
我正在使用下面的代码来尝试获取触摸的位置,但它只能在按钮之外使用。例如。如果触摸在按钮之外,它会打印控制台行,但如果不是,它就不起作用。什么是解决方案?这是代码: - (void)touche
我正在构建一个 iOS 绘图应用程序,我正在尝试实现一个撤消按钮来删除用户绘制的线条。我在变量中创建了一个图像数组: var images = [UIImage]() 每次用户在屏幕上滑动和移开手指时
在我的 Storyboard中,我有一些图像是“启用用户交互”的。在 UIViewController 中,我覆盖了 touchesEnded 函数。 override func touchesEnd
我正在使用 spritekit 制作游戏,触摸开始和触摸结束之间有明显的 100-200 毫秒延迟。 有什么办法可以加快速度吗?我需要使用 touches ended(计算用户触摸的起点和终点之间的矢
代码将返回 x1 和 y1 值,但似乎并没有通过 touchesEnded 函数运行。我的目标是创建一个矩形,从用户触摸的角开始,到用户抬起手指的地方结束。 //touch i
我有一个带有主菜单的 SpriteKit 游戏。菜单标签在 touchesEnded 上触发。这在第一次启动游戏时工作正常。 然后,第一关结束后,再次呈现主菜单。这次没有触发touchesEnded!
我有一段简单的代码,其中覆盖了 touchesBegan、Ended、Cancelled(empty block) 和 touchesMoved。如果我用鼠标单击(我在台式电脑上测试) touches
好的-所以我有一个子类 UIView 的应用程序,并依赖于 touchesBegan 和 touchesEnded。我当然指的是这些回调: - (void)touchesBegan:(NSSet *)
我正在为 iOS 开发一个应用程序,我希望用户能够在屏幕上选择一些东西,然后在选择结束时能够按住手指一秒钟,以触发其他一些东西事件。 我已经创建了很多 Action ,用于当用户通过四处滑动来标记内容
我有一个 UIView 子类,我在其中使用 touchesBegan、touchesMoved、touchesEnded 处理触摸。我注意到当我在内部开始触摸然后拖动到 UIView 外部时 touc
我有一个名为“MyView”的 UIView 子类。在ControllerA中,它有一个属性MyView *myView,并将其添加到self.view中。在myView上,有一些随机的 subvie
我是一名优秀的程序员,十分优秀!