UITapGestureRecognizer在Landscape中不起作用

时间:2016-06-04 19:12:24

标签: ios swift orientation landscape icarousel

我正在尝试为我的iCarousel项目添加点按识别器。为了做到这一点,我写了这个:

func carousel(carousel: iCarousel, viewForItemAtIndex index: Int, reusingView view: UIView?) -> UIView {
    let rView = UIView(frame: someOtherView.frame)
    let imageView = UIImageView(frame: someOtherView.frame)
    imageView.frame.size.height -= 30
    imageView.frame.size.width -= 50
    imageView.image = (images[index])
    imageView.contentMode = .ScaleAspectFit
    imageView.backgroundColor = UIColor.whiteColor()
    imageView.userInteractionEnabled = true
    rView.addSubview(imageView)
    if let gestures = rView.gestureRecognizers {
        for gesture in gestures {
            rView.removeGestureRecognizer(gesture)
        }
    }
    let tap = UITapGestureRecognizer(target: self, action: #selector(ViewController.moveCarousel(_:)))
    rView.addGestureRecognizer(tap)
    print(rView.gestureRecognizers)
    setImageToCenter(imageView)
    return rView
}

这在纵向模式下工作正常。但是,当我旋转到横向时,它不起作用。点击视图时没有任何反应。这是我在旋转屏幕时调用的内容:

override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
    super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator)
    slider.setWidth()
    trademarkCarousel.reloadData()
}

当我的设备处于横向状态时,如何运行TapGestureRecognizer?感谢。

0 个答案:

没有答案