这是我想要的UIView。其中大部分都是隐藏的,只能通过拖动可见的小部分来拖出。
我想要绘制我的视图,让它说出90%的容器,并在顶部绘制一个小矩形(可见部分),但后来我面临两个问题:
我怎样才能实现这一目标?
答案 0 :(得分:1)
当该点位于您不希望接收触摸的视图部分时,覆盖pointInside:withEvent:
以返回false。
答案 1 :(得分:1)
您可以在shouldReceiveTouch
中使用panGesture检查触摸点。
例如
class ViewController: UIViewController,UIGestureRecognizerDelegate {
var panGestureRecognizer:UIPanGestureRecognizer?
override func viewDidLoad() {
panGestureRecognizer = UIPanGestureRecognizer(target: self, action: "gestureRecognizer:");
self.view.userInteractionEnabled = true
self.view.addGestureRecognizer(panGestureRecognizer!)
}
func catchedPan(gesture:UIPanGestureRecognizer){
switch gesture.state{
case .Began:
case .Changed:
//Change frame here
case .Ended:
default:
}
}
func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
if(gestureRecognizer == panGestureRecognizer){
let point = touch.locationInView(self.view);
if (point inside your area){
return true
}else{
return false
}
}
}
}