Making a UIView receive events after showing it (setting hidden = false) - ios

I already tested the solution of setting up the alpha property from 0 to 1. However, this seems to be performance intensive operation.
What I want to do to make the UIView receive the touch events after showing it back by setting hidden = false
Is there a way to do that? I thought calling .becomeFirstResponder would solve this with no luck.

Yes, The first thing is mention by #wltrup that you have to enable userInteraction property of that view by this:
view.userInteractionEnabled = true;
and another is you have to add proper gesture recognizer on that UIView to perform specific events.

Related

.hidden = YES working but .hidden = NO not working

I have a UIImageView with a custom class in a table cell that also uses a custom class. The UIImageView is connected as a property of the cell's custom class.
The UIImageView has a UITapGestureRecognizer that calls method tapped: I'm passing the cell as the UIImageView's delegate and trying to unhide another view of cell using cell.theOtherView.hidden = NO Strangely, to hide .hidden = YES works, but to unhide isn't working.
It's hard to know what's going on without seeing the code you're working with (for example, your code might never actually be reaching the line that sets the view to be hidden), but as MattyAyOh suggested, it's worth trying
[cell.theOtherView setNeedsDisplay];
after you set cell.theOtherView.hidden = YES;. This will force the view to redraw itself.
My guess is that once it's hidden, it no longer received the Tap gesture. Try using cell.theOtherView.alpha = 0.0.
you should register your object to .h file first, then you could use hidden function

Showing / hiding accessibility elements in an overflow menu when opening a custom UITableViewCell

I’m implementing accessibility in a custom UITableViewCell class. I have a fairly simple overflow menu with a couple of buttons inside it, which are hidden until an ellipsis button is pushed that slides open and closes the overflow.
In my cell's initialiser I’m setting the accessibilityElementsHidden of my overflowContainer to YES. This seems to work, when scrolling through using VoiceOver, those views are skipped.
Then, when opening the cell, in the completion handler of the UIView animation, I set that same accessibilityElementsHidden of the same overflowContainer to NO. This doesn’t seem to have any effect, those elements are still skipped.
I’ve also tried posting UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil) before / after / when changing the accessibilityElementsHidden BOOL, but this also appears to have no effect on the situation.
Basically I’d like to toggle accessibilityElementsHidden on a couple of UIView instances at a specific point. Could anyone let me know what I may be doing wrong?
Here’s the code I fire when the overflow opens:
- (void)cellOverflowDidShow:(MyCell *)cell
{
self.overflowContainer.isAccessibilityElement = YES;
self.firstButton.isAccessibilityElement = YES;
self.secondButton.isAccessibilityElement = YES;
self.thirdButton.isAccessibilityElement = YES;
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, self.firstButton);
}
I fire the opposite when closing the cell (set all to NO and post notification again). And when initializing the cell, all I set is:
self.overflowContainer.isAccessibilityElement = NO;
Absolutely no idea why it shouldn’t be working, it appears I’m doing everything 100% correctly. If I don’t set the line in the initializer, the buttons all appear accessible (all the time). So it appears that the first call, be it YES or NO, works, but any subsequent ones are ignored.
In the visible state, you declare the overflow container to be an accessibility element. Thus, VoiceOver will allow the user to focus it rather than navigate child elements. Instead of toggling whether it's an accessibility element, keep self.overflowContainer.isAccessibilityElement set to NO and toggle the accessibility of its children, firstButton, secondButton, and thirdButton.
A shorthand for setting the accessibility of child elements is accessibilityElementsHidden. Try setting self.overflowContainer.accessibilityElementsHidden to NO when the view appears and YES when it disappears.
You may still need to trigger a layout change notification, regardless.

ios uibutton hidden: does this automatically make the button disabled?

I just have a knowledge question about UIButtons / iOS in general.
Let's say you have a UIButton. You set the 'hidden' property to YES. This makes it no longer visible in view, right? But I noticed that while it's no longer visible, it is also no longer clickable either. So, does this mean that setting hidden = YES also sets enabled = NO?
Just curious. Thanks y'all.
UIButton and all controls inherits common properties from UIView like hidden, backgroundColor, etc.
Class reference of UIView says if any view is hidden then it will not receive input events
Class reference of UIView says:
A hidden view disappears from its window and does not receive input
events. It remains in its superview’s list of subviews, however, and
participates in autoresizing as usual. Hiding a view with subviews has
the effect of hiding those subviews and any view descendants they
might have. This effect is implicit and does not alter the hidden
state of the receiver’s descendants.
you can find this over Here.
It does. Setting the buttons hidden property to YES will disable any user interaction. This is true for other UI elements as well as just UIButton.
Yes you can't touch button when it is hidden.If you wanna touch it then you must make it btn.hidden = NO;. Hidden means disable the user interaction.
Not sure. Best way to find out would be an NSLog returning button.hidden

iOS subview not forwarding touches.

I have tried this a few different ways but none of them seem to work. I have a UIView subclass that has some buttons in it. I tried adding the subview to my ViewControllers however it will not respond to touches unless I set it to "initWithFrame:self.view.frame" but then it takes All of the touches and does not pass them to the view controller. I also tried adding it directly to the window so it's on top of all of the view however I have the same issue, either it will not accept touches or it takes them all.
here is how I add it when it takes all touches for itself and does not pass them on.
ControlView *cont = [[ControlView alloc]initWithFrame:self.window.frame];
[self.window addSubview:cont];
I'm so confused as to how to fix this and I have a lot more important tasks to work on but I have been stuck for two days with this stupid subview/touch issue.
How are you handling touches? UIGestureRecognizer?
You should make sure that your uiview subclass has userInteractionEnabled = YES. That's the default but maybe it got turned off somewhere along the line.

Use UISlider without user interaction

I've got a customized UISlider that I want to use to display information to the user with and I don't want the user to be able to interact with the slider. I've tried
mySlider.enabled = NO;
but the slider becomes greyed out, which does not look the way I want it to look.
So, how do I set a UIControl to disabled without "greying" it out.
mySlider.userInteractionEnabled = NO;
Don't you think it's going to confuse users to present an enabled slider that doesn't respond to touches? A UISlider doesn't just display information, it also tells the user that the information is user-adjustable.
You should come up with your own information display that doesn't look user-adjustable.
userInteractionEnabled probably doesn't works for the UISlider (and why it exists??) but it works for its superview. So, try attaching the UISlider to another auxiliary (transparent?) NSView and then set userInteractionEnabled = NO to this auxiliary view.

Resources