There are a series UIViews arranged very close.
alt text http://www.mobilepanda.com/questiontouch.png
I hope when my finger touches some of them, my app can detect which UIView touched.
Maybe one or two or three.(because the displayed parts of each UIView are too thin).
I hope to get the middle x value of the touch, then spread the UIView where the middle x value locates and the UIViews near it.
alt text http://www.mobilepanda.com/questiontouch1.png
My way is put a transparent UIView over all these UIView to detect the touch event.
I am not sure if this is ok? or there is any better solution.(for example, make each UIView has the capability to detect the touch, mix and decide which UIView is touched.
Welcome any comment
Thanks
interdev
You don't need to do all that. The OS will decide what the center point of the finger touch is and send an event with the touch x,y coordinates to the correct view. If you make them UIButton's (a subclass of UIView) instead of UIView's the OS will do all the work for you. All you have to do is attach callbacks to each button to the functions you want called for various events (like touchUpInside, touchDownInside, etc).
Related
I have a view which is using single touch events (single finger) for drawing (lines, cycles, text, and so on).
Now I want to put this view inside of UIScrollView, which will allow zooming and panning. Of course two fingers are required to perform both zooming and panning.
What is the pattern do do that? I've found only examples when contents of UIScrollView accepts only single clicks (it contains only a buttons). Nothing what to do when contents require also touch moves.
Access the panGestureRecognizer property on the UIScrollView, and set its minimumNumberOfTouches property to two:
myScrollView.panGestureRecognizer.minimumNumberOfTouchesRequired = 2;
I'm thinking you should begin with scrolling disabled for scrollview and user interaction enabled for both. Then in touchesBegan: you should check for number of touch points. If it's only one (aka user wants to draw) you do nothing (disabling interaction for scrollview would disable it for all subviews as well). However, if the number of touch points is greater than one, enable scrolling then do
[UIView setUserInteractionEnabled: NO]
This way, no lines should be drawn on the UIView when you pinch or zoom with two fingers on the UIScrollView.
I helped developed an app that required a signature plate with in a scroll view, and a scroll view's subviews are weird to touch events, sometimes you have to hold your finger there for it to pass through the scroll view and reach the inner views, so there was a bit of a lag... but what i ended up doing was subclassing a UIScrollView and overriding the
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {}
method and if the touch landed with in the frame of the signature plate it would
[scrollView setScrollEnabled:NO]; and the drawing happened sooner and more smoother... the only problem is they couldn't scroll the scroll view from that box.. basically i created a dead spot with in the scroll view
but, that's a little wonky, i think a UITableView might work better for you... just make it 1 giant table cell, i think you will get better results....
Don't forget to enable 'Multiple Touch' for these features.
I have dynamically created a grid of 8x8 image views over which letters are displayed and assigned the tag to each.I can detect the touch on each image view through Tap Gestures but what I want now is : if the user slide its finger across the letters, i would be able to get the each image view tag. So that the letters touched can be detected(the continuous touch).
Please Help,
Thanks In Advance.
Disable user interaction on the individual image views and handle touches on the superview containing them instead. Then you can figure out which image the user's finger is over in touchesMoved.
As the other poster said, you need to handle the touch events on the superview. You could use touchesBegan/touchesMoved, or you could add a pan gesture recognizer to the superview. Personally, I prefer gesture recognizers. I find them cleaner and easier to use, so I'd go that route.
I'm making a Schedule App for Cocoa Touch and I need to be able to select a time interval just by touching the screen. I mean, the user must be able to select with its fingers a time interval within the "ScheduleView" and then Add an event.
I was thinking of making some kind of rectangular selection, similar to the one that everyone can do in Windows Desktop, but i don't know how to detect multiple touches, neither how to draw the selection rectangle. Can anyone help me?
P.S: The "ScheduleView" it's a UIView, not a UITableView
You'll need to add a UIGestureRecognizer to your view. You can detect touches as a delegate, and this case will probably do best with a UIPanGestureRecognizer. You'll set the delegate to be yourself and draw the box within -(void)panGestureMoveAround:(UIPanGestureRecognizer *)gesture Here is a tutorial.
To draw the box, you could manually draw into the view but it may be easier to reshape a UIView on top and manipulate its border width and color like this SO question.
Hi all:
I want to write a gesture recognizer on the iphone, that I cold use two finger to drag the view. Just like we use two finger on the MacBook Pro's touch pad.
If the view's size is larger than the window's size of the device, I could use two finger to drag the view. is there any good way to solve it ?
(Thanks enamrik and Naveen Thunga. I achieved my goal just now, but there is a new question that how could I know the UILongPressGestureRecognizer is over. I want call a method and set some value when my finger leaves the screen of my iphone.)
The UILongPressGestureRecognizer class has a numberOfTouchesRequired property you might find useful
Use uigesturerecognizer's properties and enable View's multitouch property. See some sample on UIGestureRecognizer that may help you.
I have a view that is moving. The view is sometimes on and sometimes off screen - it is twice the width of the screen.
In this view, there are buttons that I need to be able to click.
I've tried doing this in many ways already - using pure buttons
using touches began on UIView
I'm doing the animation using a CGPath in core animation
Any help would be most appreciated
Thanks
Whether the view is moving or not should irrelevent to the touch detection. If you have a UIButton object and are handling the UIEventControlTouchUpInside (forgot the exact name) event , it should be called when it sees a touch. Is that not working for you?