我想设计一个可滚动的按钮,位于屏幕底部(就像照片中的过滤器),它是许多页面的目录(TOC)。 我曾经写过类似下面(使用Objective-C)的代码,在iOS 7中运行良好,所以不确定这是我的Swift转换还是iOS 8问题。
tocView = UIScrollView(frame:CGRect(x:0, y:self.view.frame.size.height, width:self.view.frame.size.width, height:thumbHeight))
for i in 0 ..< pages.count {
let image = UIImage(named:pages[i].name)
var button = UIButton.buttonWithType(.Custom) as UIButton
button.setImage(resizeImage(image, size:CGSize(width:thumbWidth, height:thumbHeight)), forState:.Normal)
button.frame = CGRect(x:thumbWidth * CGFloat(i), y:0, width:thumbWidth, height:thumbHeight)
button.addTarget(self, action:"selectPage:", forControlEvents:.TouchUpInside)
button.tag = i
tocView.addSubview(button)
}
一切都很好,除了有时候滑动不起作用。当我尝试滑动时,有一半的时间似乎下面的按钮会拦截滑动,使得滑动没有发生。只有当我非常快地滑动时,滑动才有可能实现。我希望能够检测到正确的滑动或点击操作。有人遇到类似的问题吗?