Subview of UIScrollView don't resize (manually)

215 views Asked by At

I have a UIScrollView with a UIView inside of it. When I try to manually resize the UIView by code, it doesn't work. I tried to set the autoResizingMask property of the UIView to .None and I implemented the touchesShouldCancelInContentView method of the UIScrollView to return true but it still doesn't work. Here's my code :

class ViewController: UIViewController {

@IBOutlet var scrollView: CustomScrollView!
@IBOutlet var field: UITextField!



override func viewDidLoad() {
    super.viewDidLoad()

    var gesture = UITapGestureRecognizer(target: self, action: "gestureHandler")
    gesture.numberOfTapsRequired = 1
    view.addGestureRecognizer(gesture)

    scrollView.contentSize = CGSizeMake(430, 140)

    field.autoresizingMask = .None

}

func gestureHandler() {

    field.frame.size.width += 20

    var view = UIView(frame: CGRectMake(0, 0, 30, 100))
    view.backgroundColor = UIColor.redColor()

    field.frame.size.width -= 30
    field.frame.origin.x += 30

    scrollView.addSubview(view)

}

}

class CustomScrollView: UIScrollView {

override func touchesShouldCancelInContentView(view: UIView!) -> Bool {

    return true

}


}

What I get :

What I want :

Thanks for your help !

0

There are 0 answers