Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting Touch from TOP/BOTTOM

I'm a beginer on IOS Development, I've developed a simple demo of detecting multiple touch by following this tutorial:

It works fine, but my question is: when I try to start the touch from the outside of the iphone ( from TOP or BOTTOM), the touch is not detected, and when i tried to do the same thing from LEFT/Right sides, it works. Can someone explain to me, why the touch is not detected when I try dragging from the top or the bottom?

like image 872
Houcine Avatar asked Aug 26 '11 14:08

Houcine


4 Answers

It doesn't start from top because the status bar picks up the touch. You know how when you tap status bar, scrolled content goes to top? That's why status bar "steals" your touch. If you remove status bar (you can do that in app's Info.plist) you will get touches from top, even with iOS 5 and it's "pull from top" notification center. (A small pulldown handle will appear on first pulldown, and if you pull again, notification center will steal your touches.)

It should however start from bottom unless there is some kind of tab bar or other toolbar that also picks up touches.

like image 165
Filip Radelic Avatar answered Nov 07 '22 18:11

Filip Radelic


The status bar will get the touch event instead of your view. You may hide the status bar by:

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];

Or just set the Status bar is initially hidden property in the info.plist file.

In addition, if your running iOS 5, the behavior will be different when the status bar is hidden: you can get the event from your view but the system will also drop down a little floating drag bar.

If you don't want to hide the status bar, you may try to set the windows layer and put the view above the status bar(not sure whether this is allowed in the AppStore or not).

like image 36
PeakJi Avatar answered Nov 07 '22 16:11

PeakJi


I think it's desactivated because of the future release of iOS 5, who allows you to display notification center by touching from the top to the bottom of your iphone.

As I'm running on iOS 5 I can't give you more details cause I cannnot test, but I think it's the most likely answer

like image 2
Victor Carmouze Avatar answered Nov 07 '22 17:11

Victor Carmouze


Using this code in loadView of a UIViewController:

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:NO];
CGRect screen = [[UIScreen mainScreen] bounds];

UIView* mainView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screen.size.width, screen.size.height)];
mainView.backgroundColor = [UIColor whiteColor];
self.view = mainView;

mainView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth |
    UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin | 
    UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin;

[mainView release];

All touches are picked up when sliding from off the screen into it in any direction and orientation. Notice that the size of the view always occupies the entire screen.

I believe the others are correct in saying that the status bar will get the touch events if it is visible. Also, if the view doesn't span the entire screen it may not get events. For example, if the frame's y-coordinate is 20, it will not pick up the touch when sliding your finger from the top.

like image 1
nloko Avatar answered Nov 07 '22 18:11

nloko