does anyone have a working sample project showing how can a user can draw simple sketches on the iPhone, with his finger? Something like the GLPaint, but easier, without Open GL.
Something just with the basic drawing functions. I know there was a FingerSketches sample time ago, but it appears it's no longer available.
You're right, there was a FingerSketch example; I'm not sure whether it still works, and I don't think it's a good idea to publish the entire example here. But I think you can use the Touches or MoveMe samples as a starting point to learn how to react to touches.
Basically, you have to remember the last position on each touch event, and draw a line from the last to the current position in touchesMoved and touchesEnded. As usual, FingerSketch doesn't draw directly to the screen, but to a separate drawing context, and then calls [self setNeedsDisplay] to redraw itself.
Related
I am beginner for interactions on iphone. I have 3 buttons, one on the left, and the 2 other ones on the right. I would like to push the left button with finger and display a line real time stretching with my finger moving on screen that goes to the other button I am going to go to on the right - and then I reach the button on the right and release my finger the line stays on screen.
Where should I start in the manual to understand how to do something like this?
- please don't say page 1 ;-)
thanks for all the pointers so I can learn and write the code myself
Cheers,
geebee
Wow, uh, you're jumping right into the deep end.
First, the answer to your question is ... check out the Sample Code at developer.apple.com. By playing with those sample projects, and running them in the debugger, and reading that code, you can learn a whole lot about what you're trying to do.
Using those samples as your tutorial, refer to specific information in the reference docs also available at developer.apple.com. There are specific docs on the classes you'll be using (e.g. UIButton Class Reference), and there are high level guides that talk about different areas, like the Event Handling Guide for iOS, and Drawing and Printing Guide for iOS.
Here are some of the issues you're going to face, and some of the areas that you should read up on:
UIButtons are going to respond to your touch and won't allow any other view to receive that touch without some special handling in your code.
Check out samples that deal with UITouch events, Quartz 2D drawing, creating custom controls
Try doing this without any buttons first, that's fairly simple. Just figure out how to detect a TouchDownInside event, track the finger movement across the screen, and detect a TouchUpInside event, all in a normal UIView. (There may be a sample for this.)
I am developing a game for iPhone and I came across a question whether this can be done using UIAnimation or I have to switch to OpenGL.
If you see the picture above, you can realize there is a rectangle (it will have background image) having many holes in it. User is supposed to touch on holes and initiate the animation. The holes are actually on the image and are not some view. Do you know any article or tutorial I need to read in order to understand this can be done using UIAnimation?
It's more like chess. When you tap a hole, there is a view placed and moved at z-axis and then when you press the other hole, the view is moved to that hole and so on.
I believe it can be done with UIViews too. The holes can be made by using an image with "transparent" holes in it. You can place this UIView on top of a background image(if required). When touches are detected, you can animate another view on top of this view using addSubview:. You can keep this other view outside the screen bounds initially so that the animation seems like a sliding animation.
yes UIView is also an option in your case. if you feel that you will use high quality lots of graphic and will do lots of animation stuff at once on the screen, openGL will be the best or perhaps the gane you are making is a 2d game so you must consider COCOS2D "http://www.cocos2d-iphone.org/" for kick starting your game you'll surely get many effects and other glittering stuff with it. and bes of all it is openGL based..!! Performance will be too high for you..!!
Best of luck..!!
In my app, I drew a graph using Core Graphics (inside a view, inside a view). Not a graphing calc app though, it graphs patient data and marks it every six months, and it is larger than the screen, so the user needs to have some way to move around. I was wondering if there is an easy way to implement pinch to zoom, or to flick with momentum. I was planning on just using UITouch to get notified when these actions were performed, but it doesnt really give you a lot of information. For example, all you get with the pinch to zoom is the ratio that they have zoomed, and all you get with the flick is the direction that they have flicked. So, I was just going to implement basic flicks without momentum, and simple pinch to zoom without being able to move around too.
But I figured I would ask here first, to see if anyone has a better idea about how to do this (easily).
EDIT: I found lots of places that tell you how to do this with photos, but none with core graphics or something like that, thanks.
I ended up using a UIScrollView, which implements pinch to zoom, and flick automatically (well, almost).
I found a useful tutorial to get started in understanding how to Cocoa handles touch events. I've used this as a base to create a custom script, I'm trying to make a UIView draggable, very similar to the native Maps application.
I've written a custom script, using
the touchesBegan method it will
capture where the input began and
compare it to the centre point of the
UIView using some conditional
statements.
The touchesMoved method will do some
further conditional statements to
determine whether the touch start
point and the center of the view will
move positively or negative.
I've also captured the views
boundaries so it doesn't go too far
out.
it's lacking the polished finished found in other applications such as Maps, or scrolling a UITable, such as the ease effect after the user has released their fingers, and the snapping effect when it reaches the boundaries is horrible.
Is there a method that takes a view and makes it draggable like this? If not I'll continue to refine my script.
Many thanks!
Maybe you are looking for UIScrollView
I am trying to implement simple paint functionality in my iPhone app. I tried updating a bitmap with a bitmap brush, and I also tried this tutorial.
Both methods have the same problem, even though the code is almost totally different. It happens only on the device - the simulator works fine.
When I touch the screen and move my finger, the screen does not get updated. When I pause or lift my finger, then the screen gets updated. This is not a very good user experience!
I tried calling drawRect from touchesMoved directly, but found that the drawing context (which I retrieve using UIGraphicsGetCurrentContext) is invalid for many of the calls, so painting the screen myself for every touchesMoved doesn't work.
Any ideas?
Thanks for any help, this has been quite frustrating!
Henning
It sounds to me like you're not giving the main run loop a chance to update the display. Your drawing code may be taking longer to execute than the time between touch events, so the display is never updated. When you lift your finger, it does the updating because it's no longer burdened with your drawing.
You might consider optimizing your drawing to speed it up (drawing only within the dirty region of the screen, for example), using something like NSOperationQueue to queue up the heavy calculations of your drawing to run on a background thread, or selectively dropping touch drawing events to keep your response smooth.
One additional possibility is placing your heavy drawing code in a separate method and calling it via performSelector:withObject:afterDelay, with a 10 millisecond (or smaller) delay. This might give the main run loop a chance to update the display with its current state. I haven't tested this, but if I remember correctly I've seen this work.
You can't directly call drawRect:. To refresh your screen on demand, try calling [self setNeedsDisplay] from your touchesMoved method, which will setup the proper contexts for a call to drawRect:.