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
Related
I am making a type of drawer animation for iOS where a button tap in one of my views will expand that view over the other views from the bottom up. All is well, except when I want to change the button image after animation. The animation completes but then returns the view to its original position when setting the button image.
Things I have tried:
Using CGAffineTransformMakeTranslation instead of setCenter; this works perfectly, except I want to also add a panGestureRecognizer to interact with the drawer, present, and dismiss it. The transform doesn't seem to play well with this interaction
Adding the buttons programmatically thinking maybe AutoLayout is fussing with this
UIView beginAnimations as well as UIView animateWithDuration and completion block
Setting breakpoints and verifying that the movement of the view is reflected in the frame of the button before the image is changed; button frame is not still in original position, but has supposedly relocated with the view
It shouldn't matter, but my project is using TabBarController. I made a simpler version of what I'm trying to do with just the one view controller and had the same issue. The green view extends beyond the frame of the view controller's view so that when it moves up it reveals what is off-screen.
example: http://i.imgur.com/tRou0Js.png?1
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 have bunch of images inside a UIScrollView and have a tap event setup on each image. When I try to make the image full screen it actually is cut off by the scroll view. I am trying to implement a Facebook style UIImageView where the image zoom in and takes over the full screen on tap.
Does anyone have suggestion on how to approach this cause the way I am doing the image is cropped to the size of the scroll view.
Well, usually you would disable clipping, but the scrollview relies on clipping to do its job so that won't work.
My suggestion would be to push a copy of the image above the scrollview, and animate that to full screen. You should be able to get the rect using convertRect:toView: and it would be pretty straightforward from there.
btw, Is there a reason not to use a tableView for this?
When tapped hide the image and add the image at the proper place in the scrollview superview and over the scrollview. Then animate it to take the full screen.
Facebook App style UIImageView is nicely implemented in below given source code, you can take a clue from this
https://github.com/michaelhenry/MHFacebookImageViewer
i have a tableview with different kind of cells, one of which has some UITextFields's and UIButton. When i try to scroll this view with the touch starting in any of those subviews the table won't scroll and recognizes it as a 'touch inside' of a subview. I had it before with "delays content touches' but the touch inside button doesn't work well. Any ideas how i might fix this problem?
I just found i had an 'UITapGestureRecognizer' that was creating the problem. thank you for the help
Turning off "Cancellable Content Touches" in the UITableView solved this for me (in the UITableView attributes inspector under Scroll View / Touch). I got this from this SO question: Scrolling a UITableView inside a UIScrollView
From the UIScrollView:canCancelContentTouches doc:
If the value of this property is NO, the scroll view does not scroll regardless of finger movement once the content view starts tracking.
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.