Adding a UIImage on a touch event iPhone - iphone

OK i am really struggling with this!
I know had to add an image to the view, i know how to record a touch event. But combining the two is proving to be an issue.
There are lots of tutorials out there on how to move an image with touch events.
But Could anyone suggest how i might complete the following:
Add an image to the view on touch
Add the same image on another touch received by the user.
Manipulate the location of the added images when the user touches a previously added image
Any advice would be highly appreciated

Supposing that you want to simply let the image appear and disappear, you could just implement the UITouch event handling methods in the UIViewController for the view that you want to intercept the touch events in. An example on how to do this can be found in the "iPhone Programming Guide: Event Handling" at:
http://developer.apple.com/IPhone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/EventHandling/EventHandling.html#//apple_ref/doc/uid/TP40007072-CH9
Once you have managed to intercept the touch events, you can simply add the UIImageView as a subview of the view you want it to appear in.
I hope that helped a bit.

Related

UIView Receive Touch And Slide Action

I am a newbee in iOS development; and i want to develop a simple application.
In my application there is a view that is a member of xib. I want to receive user's touch and slide actions on my view to run some sliding animations.
I found some codes about this animation but i couldn't find how can i receive sliding action in UIView.
At least, i wanna explain why i used view. This view will contains two or more labes. So i couldn't be sure to choose Rect Button or UIView.
I hope you can help me.
You need to look at Gesture Recognizers. There are tonnes of resources and examples online. For example, here's an example on how to use swipe (slide) gesture recognizers.

How To control touches on UIWebView? (iphone)

I want to handle touches on UIWebView same as we can handle touches on UIView.I want to use methods like touches began,touch ended,etc in this app.I have to handle multiple events on different touching events on UIWebView.
In this app I am displaying image in UIWeb View and i have to make image size large and small on double touch and when the user taps on that image the next image should appear and again if the user double taps that image it should navigate to another page and if user swipes then also next image should appear.Thus,i have to handle four events on touching UIWebView.
Please anyone tell me how to do this.I have tried many codes but nothing has helped me.I also tried by making a uiview on uiwebview but only one event happens by this other events does not.
Thanks in Advance.
For what you want to do it sounds as if you shouldn't be using a uiwebview at all. I suggest you reconsider your app's architecture: typically both touch events AND page navigation (both of which you're attempting) are handled in view controllers. Consider implementing a view controller that will handle these events.
Also, don't solicit code and ask for it hand-delivered via email. No one wants to write your code, and you won't learn anything that way anyway.

iphone switch views by swiping fingers to left and right, similar as the stock app

I am interested in how the lower portion of the iphone stock app is implemented. The lower part of the app, where you can switch the views by swiping your finger to left/right and the "..." below the view to indicate which view the user is looking at.
It looks to me a tabview component. I am trying to look for the UI component as well as google it, but i have not yet find anything like it. Most of the examples I found are using scroll view. When you swipe the finger to left/right the scroll bar appears, and more importantly, there is no "..." under the view to indicate which view the user is looking at.
Could anybody point me to a similar example?
Thanks,
Thomas
It's a UIScrollView with pagingEnabled set to YES taking up most of the screen with a UIPageView underneath it. See Apple's PageControl sample code for details.
You can turn off showing the scroll indicators by setting the showsHorizontalScrollIndicator and showsVerticalScrollIndicator properties of the scroll view to NO.
It might also be worth checking out the PhotoScroller sample code for an in-depth example of how to do pagination using a UIScrollView. There's also a great video called "Designing Apps with Scroll Views" that walks you through paginating views using a UIScrollView in the WWDC 2010 videos. I highly recommend watching it and the other WWDC videos. You can get them by signing into the iOS developer center and scrolling to the bottom.
Also, like they tell you in the video, you don't need to use touch events or override touchesBegan:withEvent: or similar functions to make this happen. If you do it that way, you have to do lots of work to pass events that you don't care about through to the views you're showing and stuff like that. UIScrollView with pagingEnabled set to YES does all of the hard work for you.
If you don't want to use a scroll view for some reason, using a UIGestureRecognizer is the way to go. But really, just use a scroll view.
This is called touch events. more so Swipe touch on the iphone.
And here are two examples.
Heres a code snippet:
You first need to tell the application that touchesBegan.
You can find some details on the API for this. Then the delegate methods will be called automatically everytime a user touches the iphone screen.
- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
UITouch *touch = [touches anyObject];
if (touch.info & UITouchSwipedRight) {
[self changeViewRight];
} else if (touch.info & UITouchSwipeLeft) {
[self changeViewLeft];
}
return;
}
check this example:
http://devblog.wm-innovations.com/tag/touchesbegan/
Its a really good example.
Hope this helps.
Let me know if it did a little. Thanks
PK
Take a look at following link, it might be nice approach to navigate through views on swipe.
Views Navigation Using Swipe Gesture

Handling UITableCell move left (or move right) event?

I want to creat an UITableView which each cell (UITableCell) in this table can be moved left or moved right (System will be notified when user touchs down the cell and moves finger to left or right). Anybody can tell me how can i do it :) Thanks :)
I want to build a Table which each TableCell in it become a menu likes image bellow when user touch up TableCell and move finger to left or right!
I would guess this is done by watching for the touch events, being the first responder and monitor all touch events before you send them further to the UITableView under.
I think there is a source code from Apple that shows this.. think it's called Gestures or TableView Gestures... do a search on the Apple site.
Also, do read on the UIGestureRecognizer docs from the SDK. These can be attached to a certain view, I read.
Good luck, let us know if you're successful.

On the iPhone SDK, is there a way I can disable touch interactions on the textview? In a way that allows touches to be recieved by things behind it?

For my iPhone game I wrote the entire thing in OpenGL ES, and now I'm trying to overlay a TextView to display a scoreboard. The problem is now my touch input doesn't work correctly, because the Textview is recieving the touch input rather than my opengl view. Is there a way I can just disable touch interactions on the textview?
Found the answer, in case anyone else runs in to this:
[textView setUserInteractionEnabled:false];
It does in fact send touches to the things behind it.
UIView should have a property that you can set to enable or disable touch interactions, now will it make it so the text view is no longer in the way and the view underneath it will pick up touch events? I dont know youll have to check :)