Removing views from UIScrollView - cocoa-touch

I have two UIScrollViews that I move images between. The user can drag and forth between the scroll views. I am trying to animate the movement of the image from one scroll view to another. In -touchesMoved (handled in my UIViewController which has two custom UIScrollViews that intercept touch and sends to my UIViewController), I am trying to set the "center" of my UIImageView that is being moved. As it is moved, the image gets hidden behind the UIScrollView and not visible. How do I make it appear on top of the UIScrollView? I am able to handle the -touchesEnded properly by animating in the destination scroll view.
I am also confused about -convertPoint:fromView: usage in the iPhone Programming Guide (See Chapter 3, Event Handling). If the touch coordinates are in window coordinates, to change my view (UIImageView inside a UIScrollView which is inside a UIView and inside a window) center don't I have to use -convertPoint:toView:, i.e.,
imageView.center = [self.view.window convertPoint:currentTouchPosition toView:imageView];
What am I missing?

You can use the method - (void)bringSubviewToFront:(UIView *)view for making the image view the front most view.
Johan

It depends on how you structured your views. If both scrollviews and the imageview are at the same level, it should work. If the imageview is a subview of one of the scrollviews, you can try bringing the scrollview to the front. That way also the imageview will be drawn over the other scrollview.
Johan

I have a View Controller with two ScrollViews. Images are added as subviews. ScrollViews are already in the front. I tried bringing scrollview to the front and also imageview of the scrollview to the front. But somehow when i drag, the center of the image goes over my other scrollview2 which i also tried sending back. But does not seem to work. Here is what i do, in TouchesMove (inside a ViewController)
view= [[scrollView1 subviews] objectAtIndex:currentImageIndex];
[self.view bringSubviewToFront:scrollView1];
[scrollView1 bringSubviewToFront:view];
[self.view sendSubviewToBack:scrollView2];
scrollView1 and scrollView2 are two scrollviews that are part of the ViewController's view.
Does this make sense ?
thanks
mohan

Related

How do automatically resize an NSPopover with auto layout

I currently have an NSPopover subclass which sets it content view controller to a custom NSViewController meant to represent a tab view:
self.popover.contentViewController = tabViewController;
self.popover.animates = YES;
I'm rolling my own "tab view controller" because I've heard that NSTabViewController doesn't play well with animations. I'd like to use auto layout so I don't think I want to mess around with the popover's contentSize property. When I change tabs the popover correctly changes its size, however, it doesn't animate the change. Furthermore, I have a cross-fade animation that occurs when the tab view switches and the popover doesn't resize until after the animation finishes.
First, I'd like to figure out how to get the popover resize to animate and then I'll worry about getting the animation in sync.
Thanks

How to zoom UIScrollview together with added UIImage

I have a background image that is added to UIScrollView with zoom enabled. I am trying to add additional UIImage's on top of the background image that zoom together with the background image?
The idea is to have a background with multiple playing cards were the user can either see the whole playing field with small playing cards or zoom in the whole background including the playing cards for better views on the playing cards.
Your UIScrollview should contain a single zoomable UIView subview. That subview should contain your background UIImageView and all of the card UIImageViews as it's own subviews (if you add the background image first, it will be layered at the back of the resulting composite view)
The containing UIView that is the immediate subview of your scrollview should be the return value to the UIScrollviewDelegate method
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
You can manage your view hierarchy through a UIView's subviews property, which is an NSArray of views. They are layered in the order of the array, so the first view on the array will be at the back when the views are composited for display.
Well you could use the scrollviewdidzoom delegate method to notify you when the scroll view has been zoomed in and out.
From there you could do a number of things like present new UIImages at a specific zoom level using the scrollView.zoomScale property.
Let me know if this helps.

Zooming the whole screen with UIPinchGestureRecognizer

I was trying to add a pinch gesture zoom-in zoom-out feature to a UITextView and then I decided that adding a pinch gesture which zooms the whole screen, covering the whole view hierarchy is a better and more general solution. But I am confused about how to do it: Should I change the frame sizes of all UIView objects or should I somehow scale them? What is the most correct way to do it?
Put all your views in a UIScrollView and then return the view in this delegate method of UIScrollView
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView

Rotate UIViewControllers in UIScrollView

I have UIViewController with UIScrollView in it.
UIScrollView contains multiple UIViewControllers (something like PageControl Apple example).
Each inner UIViewController in UIScrollView is able to handle the change of UIInterfaceOrientation and to redraw it's view.
But when the UIViewControllers are in UIScrollView the rotations events never reaches inner UIViewControllers.
How can I make those inner UIViewControllers to handle rotation events?
Thanks in advance.
Only a viewController in a viewController structure (like tabbarcontroller or navigationcontroller) gets (and handles) rotation events. If you just added the views of some viewControllers, they won't actually rotate, but they will change their framesize accordingly to the new size of the main view. In general you should use autoresizingMasks on every view. Read about them in the documentation.
But in a scrollView there is probably no autolayouting possible. You could overwrite layoutSubviews: in your main view to handle the layout of all scrollView subviews based on the scrollView frame.
Perhaps you can detect when the device is rotated, then using the transform property apply the necessary rotation programmatically using CGAffineTransformMakeRotation(-M_PI_2), for example...

Need help with refreshing UIView in iPhone SDK

I have a simple drill down navigation app. On the detail view, I am drawing a few 20x20 sized UIImages, depending upon the row selected in the navigation items. These images are drawn as subviews over the detail view when a row is selected.Now when I get to the "detail view" I have set up a couple of buttons, which when pressed, will rearrange the small images. For this I need to clear the previous images and redraw them at different places in the view. I have a method like:
[MyView changeImagePositionwithPosnumber:"number selected by buttons"]
I cannot pass this method when the button is pressed since it draws over the existing images.
How do I refresh the view to pass this method ? Do I need to implement draw rect for this?
I do not quite understand drawrect and am not sure how to implement it.
In short whatever the navigation controller does when you go away from detail view, I want to do, so I can refresh my view and draw new images on it.
Any help on this is greatly appreciated. I am still a newbie.
This worked for me:
UIView *view:
for(UIView *subview in [view subviews]) {
[subview removeFromSuperview];
}
Thanks