Sangharsha
Sangharsha

Reputation: 88

Disabling the touch of every view in view controller

I am doing a project where i am creating a view with animation. While view is being created, i want to disable the touch in every view in view controller. so i did the following code.

private func addInScrollView(){
    self.view.userInteractionEnabled = false
    createCardView()
    self.view.userInteractionEnabled = true
}

But the touch is not being disabled. How to accomplished this task?

Upvotes: 0

Views: 1888

Answers (4)

Dovahkiin
Dovahkiin

Reputation: 1239

You can create a new UIView on top of your existing view(obj-c code, but hopefully will give you an idea)

CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
UIView *newView = [[UIView all]initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];
[self.view addSubview: newView];

When your animation is done, remove it

[newView removeFromSuperView];

Upvotes: 1

Candost
Candost

Reputation: 1029

This is a good solution for your task.

self.view.subviews.map { $0.userInteractionEnabled = false }

Upvotes: 3

Memon Irshad
Memon Irshad

Reputation: 972

Try this code

 override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {

    let tCount = touches.count
    var touch : UITouch!
    touch = touches.first as? UITouch
    var touchLocation = touch.locationInView(self.view)
    if CGRectContainsPoint(yoursubview.frame, touchLocation)
    {
      println("view clicked")
        return
    }

Upvotes: 0

soumya
soumya

Reputation: 3811

Hope this helps you:

Disable user interactions:

  UIApplication.sharedApplication().beginIgnoringInteractionEvents()

Enable user interactions:

   UIApplication.sharedApplication().endIgnoringInteractionEvents()

Upvotes: 0

Related Questions