Home Child UIViews unable to recieve touch events
Reply: 1

Child UIViews unable to recieve touch events

DwellingNYC
1#
DwellingNYC Published in 2017-11-14 21:20:31Z

I have a UIViewController that embeds a UITableView. This table view is 3/4 the size of the entire screen in height. the remaining 1/4th of the UIViewController has a rounded UIButton that triggers a new UIView on top of the parent view. (UITableView).

Upon instantiating and calling a UIView with a background that is set to: self.backgroundColor = UIColor(black: 1, alpha: 0.5) it would normally fill the the entire view with a black see through background that will then have an additional UIView with the following constraints:

Leading: 10
Trailing: 10
Top: 50
Bottom: 50

this in turn gives me a 'Card' effect on top of the tableView. This 'Card' view then has a UITextview property that is supposed to show the keyboard when the user taps the view with the textview embeded.

The Problem: Upon selecting the UITextview, or even touching this 'Card' view, the background table is being selected and interacted with. Nor the 'Card' textfield raises the keyboard nor does it make itself solely interactive as the parent table controller seems to be getting the touch events.

Is there any solution to this problem that is encountered in iOS 11? I never experienced this issue in iOS 10. I am using iPhone X for further note on my issue.

Here is an example of the actual issue occurring.

NOTE: If I were to select the dark area of the card itself, the table view would recieve touch events but not the text area within the card view. The reason this card view has the keyboard showing is because I called it manually in code with the textview.becomeFirstResponder method.

ADDITIONAL NOTES: I have also enabled the isUserInteractionEnabled = false on the overall presenting child view. Still does not work and parent view receives touches only.

Code for the Card

class Card: UIView {

// instantiating the textview 
var textview = UITextview()
var cardView = UIView()


private override init(frame: CGRect) {
    super.init(frame: frame)

    self.backgroundColor = UIColor(black: 1, alpha: 0.5)    
    self.cardView.backgroundColor = UIColor.white
    self.cardView.layer.cornerRadius = 8

    // Just demo the textview
    self.textview.frame = CGRect(x: 10, y: 100, width: 300. height: 100)



    self.addSubview(cardView) // adding the cardView as a subview to the background colored view
    cardView.addSubview(textview)

}

required init?(coder aDecoder: NSCoder) {
    fatalError("Error")
}

private func ConstrainCardWith() {
    // Constraints 

}


}
 extension UIView {

func Width()-> CGFloat {
    return UIScreen.main.bounds.size.width
}
func Height()-> CGFloat{
    return UIScreen.main.bounds.size.height
}
}
Suin Dong
2#
Suin Dong Reply to 2017-11-15 09:04:46Z

The question is your container view(cardview) has no frame, so your child view(textview) can not be touch cause it is out of bounds, so just add some frame in your card view will solve this question

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.326527 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO