Nico
Nico

Reputation: 6359

How can I drag my UIView only from a specific area of this UIView?

This is the UIView I would like to have. Most of it would be hidden and could be dragged out ONLY by dragging the little visible part.

enter image description here

I thought about drawing my view up to let say 90% of its container and on the top, draw a little rectangle (the visible part) but then I faced 2 problems:

How can I achieve that?

Upvotes: 0

Views: 464

Answers (2)

Leo
Leo

Reputation: 24714

You can use panGesture,in shouldReceiveTouch check the touch point.

For example

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
        }
    }

}
}

Upvotes: 1

rob mayoff
rob mayoff

Reputation: 385500

Override pointInside:withEvent: to return false when the point is in the part of the view where you don't want to receive touches.

Upvotes: 1

Related Questions