I need to figure out how in the world do I create object instances (an image) and place them on the screen and have it draggable. I know how to draw an image (png) onto the screen, but how do I make it draggable?
Create sublclasses of UIView where you override the touchesEnded method. Inside this method alter the coordinates of the view to match those of the most recent UITouch, and that will give you basic draggable views.
Related
I have an embedded Page View Controller inside my VC.
What is the best solution to add a tap gesture on the image, so that it will open in a full screen with zoom enabled / paging between the images?
Should I try to animate this in my current VC or should I open it inside another VC?
Thanks in advance,
I would animate the page view controller to fill the screen instead of adding a new UIViewController, here is why:
Memory: You already have the images loaded once, no need to create a new UIViewController and re-load again. Also adding another UIViewController to the stack isn't the end of the world but should be avoided if possible.
Code: You'v already written code to handle the content size and addition of images to the page controller. Copy and pasting into a new UIViewController would be extremely redundant.
Animation: If you wanted to animate the photo going to full screen the best way would be to animate the frame of the existing page controller. Just make sure to update the content size after animating.
I want to be able to place images in an iPad app from a given directory and then let the user resize the image and move it around on the screen.
My question is: what's the best view to use that would allow user to resize the image (with gesture recognition) and move it around on the screen?
Thanks in advance
Quartz 2D
http://developer.apple.com/library/ios/#documentation/graphicsimaging/conceptual/drawingwithquartz2d/dq_overview/dq_overview.html#//apple_ref/doc/uid/TP30001066-CH202-TPXREF101
Can draw anything you want.
Control with gestures
You're looking for UIScrollView with the viewForZoomingInScrollView: delegate method implemented.
Since you want to display an image, add a UIImageView to the scrollview and return it in the delegate.
I found a ColorPicker (ILColorPicker) that takes the whole screen on an iPhone. I want to use it in my iPad app (XCode4 using StoryBoards)... it's asking me to "In your view controller's XIB, add a UIView and then set it's class to ILColorPickerView ". I don't want to use the entire scene, just a small part of it... is there another way I can accomplish this? (using Layers, frames, etc)?
You could programmatically create a popover (UIPopoverViewController), and put the color picker as the view for your popover.
At the moment I'm working on an iPad explore game which has a hexagon tile map.
I've created a UIScrollView that contains a background view (the game map) and buttons in the form of hexagons (for interaction). I add every UIButton to the view via addSubview.
But... when I add more than 100 buttons the view gets laggy (no surprise here). But what should I do to solve this?
Example:
scroll view http://img233.imageshack.us/img233/5527/screenshot2011090110353.png
Adding UIButtons isn't the way to go here. You should probably draw the "buttons" in a custom -drawRect: method and use -touchesEnded:withEvent: to decide what the user wanted to do.
In my app i want to drag a image any where in the view and want to resize the image by pinching,gestures.
I am able to drag the image any where by using - (void) touchesBeganNSSet*)touches withEventUIEvent*)event
and - (void) touchesMovedNSSet*)touches withEventUIEvent*)event .
But am not able to resize the image.
The pinch-to-zoom behavior is given to you automatically by the UIScrollView class. Add one in place of your existing image view, then add your image view as a subview to the scroll view. Make sure the scroll view has a delegate.
The scroll view will call the delegate's viewForZoomingInScrollView: method. Make sure it returns your image view.
Then, just set the minimumZoomScale and maximumZoomScale, and the behavior should happen automatically.
HTH