所以我想在我的应用程序中使用点击手势识别器,用户不必滚动屏幕我希望手势识别器只位于应用程序的一侧,例如从左右 30 度。
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var scrollView: UIScrollView!
var images = [UIImageView]()
var contentWidth: CGFloat = 0.0
var contentAdded = false
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
if !contentAdded {
contentAdded = true
for x in 0...2 {
let image = UIImage(named: "icon\(x).png")
let imageView = UIImageView(image: image)
images.append(imageView)
var newX: CGFloat = 0.0
newX = view.frame.midX + view.frame.size.width * CGFloat(x)
contentWidth += view.frame.size.width
scrollView.addSubview(imageView)
imageView.frame = CGRect(x: newX - 75, y: (view.frame.size.height / 2) - 75, width: 150, height: 150)
}
scrollView.contentSize = CGSize(width: contentWidth, height: view.frame.size.height)
}
}
}
最佳答案
你需要 UIScreenEdgePanGestureRecognizer
/*! This subclass of UIPanGestureRecognizer only recognizes if the user slides their finger
in from the bezel on the specified edge. */
NS_CLASS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED @interface UIScreenEdgePanGestureRecognizer : UIPanGestureRecognizer
@property (readwrite, nonatomic, assign) UIRectEdge edges; //< The edges on which this gesture recognizes, relative to the current interface orientation
@end
关于ios - 如何在 UIScrollView 中使用 UIGestureRecognizer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50671615/