I'm using an MBProgressHUD inside of a UITableViewController. While I am able to get the HUD to display successfully, the HUD intercepts all of the screen's touch notifications and prevents scrolling in my UITableView.
I know that the intended functionality of MBProgressHUD might be to lock up the interface (say, during a blocking operation), but I want to know how to forward the touch events to the proper places regardless.
Any ideas?
The MBProgressHUD is a subclass of an UIView so you have to disable the user interaction with it. So:
youMBProgressHUDPointer.userInteractionEnabled=NO;
Figured it out. The following code needs to be added to MBProgressHUD's code:
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
// UIView will be "transparent" for touch events if we return NO
return (NO);
}
Check my answer here. The MBProgressHUD blocks interactions at application level. You need to devise a way to get around that by putting some custom logic.
Related
I have a custom CCNode that I am using for providing notifications on a popup basis. I am trying to disable the background when the CCNode is popped up but allow user interaction on the new CCNode.
I can disable the parent UIView by using the following when the popup is called
[[[CCDirector sharedDirector] view] setUserInteractionEnabled:NO];
In the class for my custom CCNode notification I have the button set to the following to try and override the previous code so that the button is the only touchable event
_buttonOK.userInteractionEnabled = TRUE;
However this is not working and the whole view's user interaction is disabled. How would I override this to enable only the _buttonOK to be touchable?
Thought it's not the prettiest way to do it, you can create a CCMenuItem with 100% width&height without any method. Everything under this CCMenuItem won't be clickable and you can add what you want as enabled on top of the CCMenuItem.
so... you would have something like:
Interaction Enabled Nodes > CCMenuItem without any method > Background without interaction.
Hope it helps :)
I am new to iOS development. I have a custom drawn view which is composed of multiple subviews covering the target area on screen. Specifically this is a board game like chess where I used a view for each square. The squares are created as subviews on a UIView. There is one UIViewController for this. From what I read, I have to have touchesBegan, touchesEnded etc calls in my UIView to handle these. But none of these functions are getting called. I added these calls on the base view and all the subviews. So -
How do I simulate these touch events in the iOS simulator? A mouse click is not calling the touchesBegan ,touchesEnded calls on any view.
Ideally I would like to handle these in the UIViewController because I want to run the touch through some logic. Is that possible? How do I achieve it?
Please refer THIS
It is tutorial in Apple sample codes it describes how to handle touches very nicely.
Just run the sample code and go through description you will get clear idea how touches work un iOS.
Turns out when I add the view programmatically and not through the storyboard the userInteractionEnabled variable is set to NO by default. After setting it up, I get the touchesEnabled call getting called in the view.
Check this :
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
if(![touch.view isKindOfClass:[yourView class]])
{
}
}
Hope this will help.
Scrolling is not stopping when I touch over the contact labels. How can I add this feature for this open project.
https://www.cocoacontrols.com/controls/scroller
If I touch the background, it is working perfectly. I would like to have same thing for the contacts labels too.
Basically, it uses scrollview and there is an animation while scrolling. I can not make stop it when I touch over the labels.
Any help is welcome.
Though I am unfamiliar with the scroller project, maybe this can at least get you on the right path.
The likely reason why touching the contacts isn't stopping the scrolling is because the labels are receiving their own touch events for their own purpose, which is probably the desired behavior, since you would probably want to touch one of the contacts and have it do something. It's possible that since the touch events are being intercepted in that view for that reason, that you can not interact with the scroll view using the same event.
You may need to set the userInteractionEnabled property of the view surrounding each contact to false until the scrollview has stopped scrolling. There are several ways you could do this, but this might be enough to get you started on a good solution.
My condition may be similar with yours.
I build a scroll view in storyboard and a view is added to the scroll view.All of my UI component was placed in the content view including two textfields.Generally speaking, I would like to rewrite the - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event method, and end editing actions in this view.
However,rewrite the method in scrollview's superview has little help.But when I subclass the view and rewrite that method in this subclass Every thing is OK.
According to my condition ,subclass the view and rewrite - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event.Process the logic in view level.
Background: I need to look at every UITouch that happens in an application and see if the UITouch is NOT inside a certain UIImageView.
WildcardGestureRecognizer looked very promising and I tried it. (Code is here):
How to intercept touches events on a MKMapView or UIWebView objects?
It worked great for a sandbox/quickly-created application. However that application didn't reflect the complexity that the actual target project has. The target project has a Table View Controller and more.
After adding the WildcardGestureRecognizer to the more involved iPad application, I see that none of the other controls work after the gesture recognizer is added and one click happens.
Here's some code where I was playing with the idea. Again, the sandbox code does not yet have controls on it (such as a Table View Controller or even a UIButton) to see if they work after adding the gesture recognizer to the UIWindow.
Should I pick something other than the UIWindow to add the gesture recognizer to or am I going to run into the same problem regardless? Is there a better way?
sandbox code: https://github.com/finneycanhelp/GestureKata
You might want to try another approach: create a UIWindow subclass, use that in your XIB and override hitTest:withEvent:. It returns the view that has been "selected" to receive the touch events.
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
UIView *v;
v = [super hitTest:point withEvent:event];
if (v == myImageView) {
// Do something. Maybe return nil to prevent the touch from getting
// sent to the image view.
}
return v;
}
Overriding this method can also be helpful when debugging.
I am subclassing UIControl to compose a custom control that contains different standard controls.
For this discussion let's assume that my custom UIControl contains a UIButton only.
What I would like to achieve is that clicking anywhere in the custom UIControl generates a click event for that custom UIControl. The standard behavior is that the UIButton will process and consume (i.e. not forward) the click event.
As subclassing UIButton is discouraged, I can't really find a straightforward way of achieving this.
Any suggestions?
I came up with a simple solution that doesn't need subclassing of the UIButton.
In the action method defined for the UIButton's TouchUpInside control event, I have added the following line of code:
[self sendActionsForControlEvents:UIControlEventTouchUpInside];
This results in the TouchUpInside control event being called, when clicking anywhere in the custom UIControl.
UIViews have a method called -hitTest:withEvent: that the event system uses to crawl the view hierarchy and dispatch events to subviews. If you want a parent view to gobble up all events that might otherwise be dispatched to its subviews, just override the parent's -hitTest:withEvent: with something like the following:
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
if(CGRectContainsPoint([self bounds], point)){
return self;
}
return [super hitTest:point withEvent:event];
}
UIButton is designed to process touch events. You can either set userInteractionEnabled to NO to have the button not accept any touches, or you can use addTarget:action:forControlEvents: on the button to have it call a method on your class when the button is touched.
BTW, where is subclassing UIButton discouraged?
Often I find useful user interaction related tasks in UIResponder class, which is the super class of UIControl - UIButton.
Read about – touchesBegan:withEvent:, – touchesMoved:withEvent:, – touchesEnded:withEvent:, – touchesCancelled:withEvent: in http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIResponder_Class/Reference/Reference.html You may find ways to customize user interaction for your UIButton. By the way, I don't think there will be any problem subclassing UIButton, no matter what you've heard, as long as your implementation is correctly added to the super class implementation, or does responsibly override it altogether.