ios - 如何在 UIScrollView 中使用 UIGestureRecognizer

标签 ios iphone swift uiscrollview uigesturerecognizer

所以我想在我的应用程序中使用点击手势识别器,用户不必滚动屏幕我希望手势识别器只位于应用程序的一侧,例如从左右 30 度。

first image

second image

third image

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/

相关文章:

iphone - UIActivityIndi​​catorView nillify 使其崩溃

iphone - 当我实现 -scrollViewDidScroll : of UIScrollViewDelegate in an UITableView? 时我必须调用 super

ios - 使用 SwiftUI 点击该通知时如何重定向到列表中单元格的详细 View ?

node.js - Alamofire ServerTrustPolicy 总是使 ServerTrust 失效

ios - 如何在 SKView 之上添加 SCNView

当使用 Unity3D 和 OneSignal 订阅推送通知时,iOs 因 NSInvalidArgumentException 而崩溃

iOS5 无法读取 Riven.bundle 的符号(找不到文件)

ios - 是否可以进行自定义反向地理编码?

iphone - 在我的 iPhone 应用程序中调用 rss

iphone - 无法从数据库 ios 中删除数据