gpt4 book ai didi

ios - 嵌套 ScrollView 中的 UIButton 在点击时突出显示但不触发 Segue 或 IBAction - Swift

转载 作者:行者123 更新时间:2023-11-28 10:20:31 25 4
gpt4 key购买 nike

我有一个位于嵌套 ScrollView 中的 UIButton(水平分页 ScrollView 中的垂直分页 ScrollView )。我的问题是当我点击它突出显示的按钮时,它不会触发我链接到的 segue。然后我尝试将它链接到一个 IBAction 函数,我在其中放置了一个断点,当我点击按钮时我没有击中该断点,所以我的按钮也没有触发 IBActions。

我试过为两个 ScrollView 关闭延迟内容触摸,但没有用。所做的只是让按钮在我点击它时立即突出显示,而不是在突出显示之前稍微加权。无论哪种方式,我的按钮在我点击它时都会突出显示,但我的导出(segues 或 IBActions)都没有触发,我认为这很奇怪。我在网上发现其他人也有类似的问题,但他们的按钮甚至没有突出显示。我的亮点,所以我知道它从用户那里得到输入。

下面是我如何实例化嵌套 ScrollView 。主要的水平 ScrollView 是在我的 Storyboard中创建的,然后在它的 ViewController viewDidLoad 方法中我这样做是为了嵌套垂直 ScrollView 。垂直 ScrollView 包含我的按钮。

let readingVC = storyboard!.instantiateViewControllerWithIdentifier("ReadingViewController") as! ReadingRingViewController
readingVC.read = reading.minutesRead
readingVC.goal = reading.minutesGoal
readingVC.selectedDate = selectedDate
readingVC.today = today
let readingView = readingVC.view
let scrollPage2 = UIScrollView(frame: CGRectMake(readingView.bounds.size.width,0,readingView.bounds.size.width, readingView.bounds.size.height))
scrollPage2.addSubview(readingView)
scrollPage2.contentSize = CGSize(width: readingView.bounds.size.width, height: readingView.bounds.size.height*2)
scrollPage2.pagingEnabled = true;
scrollPage2.alwaysBounceVertical = true
scrollPage2.userInteractionEnabled = true
let readingBottomView = storyboard!.instantiateViewControllerWithIdentifier("ReadingBottomViewController").view
let scrollPage2Bottom = UIScrollView(frame: CGRectMake(0,readingView.bounds.size.height,readingBottomView.bounds.size.width, readingBottomView.bounds.size.height*2))
scrollPage2Bottom.addSubview(readingBottomView)
scrollPage2Bottom.contentSize = CGSize(width: readingBottomView.bounds.size.width, height: readingBottomView.bounds.size.height)
scrollPage2.addSubview(scrollPage2Bottom)
scrollPage2.sendSubviewToBack(scrollPage2Bottom)

这是我的按钮所在的 viewController 的代码。我已将它链接到 IBAction,并将它链接到另一个 viewController 作为推送 segue

@IBAction func start(sender: AnyObject) {
var x = 0
var y = 0
x = y + x
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "StartReading" {
let destVC = segue.destinationViewController
}
}

最佳答案

我解决了我自己的问题。按钮的操作不起作用的原因是因为我将按钮所在的 View 添加为 subview ,但忘记也将按钮 View 的 View Controller 添加为 subview Controller 。因此,在实例化 readingVC 并设置其成员变量后,我在以下代码行中插入了以下行:

self.addChildViewController(readingVC)
readingVC.didMoveToParentViewController(self)

现在按钮完全按预期工作

关于ios - 嵌套 ScrollView 中的 UIButton 在点击时突出显示但不触发 Segue 或 IBAction - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35787834/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com