UIView is not receiving the touch event - iphone

I'm beginner in Ipad development, so I'm trying to do an application that will have some of the twitter application features.
The issue is that I have a UIViewController which has the content. When you click on a image it should show a view that has a video in it, all above each others (as in twitter APP), the issue is that the view is appearing and it shows the subviews in it, but it dose not receive any touch event and doesn't get the background color.
So can you help me?
thanks :P

Make sure that the userInteraction is enabled for the image view. You can do it from the Interface builder, or alternatively, do -
myImageView.userInteractionEnabled = YES
You can then add gesture recognizer to that imageView- in your case a tap gesture recognizer. That should work. To add a gesture recognizer:
UITapGestureRecognizer *tapGestureRec = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleTap:)];
[myImageView addGestureRecognizer:tapGestureRec];
Then handle the tap in the handleTap: method.

Related

Detecting touch event outside certain UIView

In my app, to click a button will pop up a UIView, now I want to click anywhere outside of the UIView to dismiss the UIView.
I have tried adding a large transparent button under the UIView, invoke the button action to dismiss the UIView, but the button can't be expanded to Fullscreen because of the top navigationbar and bottom tabbar
Is any other way to achieve?
A giant UIButton it's not very good solution to your problem. You can simple use a UIGestureRecognizer for that.
You can allocate one like this:
UITapGestureRecognizer *tapImageRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(dismissPopUp)];
Then, just add the gesture to the views you want to respond to the selector chosen.
[self.view addGestureRecognizer:tapImageRecognizer];
and possibly others
[self.navBar addGestureRecognizer:tapImageRecognizer];
//etc
Just don't forget to implement the method used by the gesture recognizer
-(void)dismissPopUp
{
//your dimiss code here
}

Make UITextView react to tap event. (iphone)

I'm trying to implemet a scrollable Text view (not editable) that display some help information etc. and when the user is done with it all he has to do is tap it and it will disapear/hidden and the user will be back in the main screen.
The UITextview not reacting to tap event (or i'm not sure how to make it react to the tap event).
Any idea how to implement this ?
I also tried to put it inside a transparent button so i can capture the tap but then i cannot scroll the text view as it seem to be behinde the button.
i'm new to iphone , any help... gr8
Thanks
How about adding a tap gesture recognizer to the text view?
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(textViewTapped:)];
[yourTextView addGestureRecognizer:gestureRecognizer];

UITapGestureRecognizer interefering with UIPinchGestureRecognizer

I have a view controller that attaches a UITapGestureRecognizer to its main UIView, and enables the user to tap the screen to make the status, navigation, and tool bars reappear / disappear (like the photos app). I also have a UIScrollView attached to the main UIView which implements zooming and thus has its own UIPinchGestureRecognizer and UIPanGestureRecognizer to implement scrolling and zooming.
The problem I'm having, is when going to zoom / scroll the UIScrollView, it's very sensitive to picking up the UITapGestureRecognizer which is attached to the main UIView. It seems a lot of the time the UITapGestureRecognizer gets triggered when it shouldn't. Anyone have any ideas on how to fix this for versions of ios below 5.0? Is there someway I can override the simultaneous gestures delegate method for the UIGestureRecognizerDelegate in the UIScrollView and prevent the UITapGestureRecognizer from firing during other gestures?
Use the requireGestureRecognizerToFail: method.
[tapGestureRecognizer requireGestureRecognizerToFail:pinchGestureRecognizer];
This call tells the tap recognizer to wait for the pinch recognizer to fail.

UIButton not working when single tap gesture is added to superview

I have a UIButton set up and hooked up to an action in my view controller as usual. Just this by itself works fine.
Now, I have added the following to my view controller to set up a single tap:
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer * singleTapGesture = [[UITapGestureRecognizer alloc]
initWithTarget:self
action:#selector(handleSingleTap:)];
[self.view addGestureRecognizer:singleTapGesture];
[singleTapGesture release]; }
Now, every time I tap the button it looks like it was tapped but it fires the gesture recognizer code instead of the button action.
How can I make it so that the button works when I tap the button and the tap gesture works when I tap anywhere else in the view?
Your problem is similar to this question which hopefully has been answered ;)
UIButton inside a view that has a UITapGestureRecognizer
Here is a simple solution
singleTapGesture.cancelsTouchesInView = NO;
Andrew,
It seems to me that you want to call a function when the user taps any where except the UI objects.
so my suggestion is that create a custom button of the size of screen(320x460 assuming that the grey bar is shown) place it back of all the objects in the IB. By this time you will be able to see a UIButton with almost 0% opacity.
and from the IB drag the selector option of the custom button to the file owners and select the function that you want to call and you are all done.
Its simpler than what you were attempting in your code

gesture recognizer for whole UIView

I want to find a way to animate a whole UIView which contains some ui components within it. Here's my code snippet:
UIRotationGestureRecognizer *rotationGesture = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:#selector(rotatePiece:)];
[piece addGestureRecognizer:rotationGesture];
[rotationGesture release];
the "piece" is a uiview here which I want to rotate and it works perfectly fine. But when I add some other UI components (like UIbutton) inside it (piece view), gestures are not recognized properly when user touches on those UI components. Essentially, I want the parent to listen to the gestures even when user touches the child object.
Any ideas?
you just need to addGestureRecognizer to your subviews you add to your view. As in the rotate piece method you might be rotating your original view only,so it will work fine.
You can add a transparent UIView to cover the whole area and add the gesture recognizer there.