Zoom in many UITextView - objective-c

I have many UITextView and UIImageView inside UIScrollView.
This UITextViews and UIImageView I create dynamic.
How can I put zoom in and zoom out if this elements I create dynamic? Sometimes I have one UITextView and one UIImageView, sometimes I have two UIImageViews and one UITextView and etc...

You will need to figure out the contentSize for the UIScrollView. Loop through all of the UIViews added and determine the one in the lowest-right corner then grab it's frame origin + size and that should be the full size then set the scrollview.contentSize to that CGSize value.

You'll need to create a view (either UIView or a subclass of UIView) with everything you would like to zoom in on on it and return it in the UIScrollView's viewForZoomingInScrollView: delegate method.
Obviously set the contentSize, maximumZoomScale and minimumZoomScale properties accordingly.

Related

Why UITableView becomes size(0,0) and pos(0,0) when manipulating other UImageViews in the same View (and viceversa)?

I am developing a Tab-Based Application. I have included different subviews (UIImageView and UITableView) in the main view. When I change the size and position of the UIImageView, the UITableView dimension change to x=0, y=0, w=0 and h=0. On the opposite case, when I modify UITableView, UIImageView moves to x=0 and y=0, and it changes to w=0 and h=0.
Why is this happening?
Thank you in advance.

Make a UITableView that is not 100% width

I would like to make a grouped UITableView where the cells are not 100% width, this is because I want to show the background, and each cell will have rounded corners.
Sort of like this;
However, I'm not sure how to do this using Storyboard; or is it only something you can do in code?
Ideally, I'd like the whole area scrollable; but make the cells appear less than 100% width
One possibility: you could use a container view. That is, in the view controller where you want this table view to appear, add a Container View in interface builder and set the size however you like. Then add a UITableviewController to your storyboard. Embed the UITableviewController in the Container View by control dragging from the Container View to the UITableviewController and selecting embed.
i think you can use customized cells, set special backgrounds (with rounded corners etc.) and replacing views to have a padding to the borders. but not sure if it really works well. in the example you would have 3 different cells in one section.
Not sure if this is the best solution; the one I have so far is...
In storyboard
Create UITableView as normal as child of a UIView, set up
delegates, data source as required
Add a UITableViewCell to this
Create my own custom subclass of UITableViewCell;
- (void)setFrame:(CGRect)frame {
frame.origin.x += kInset;
frame.size.width -= 2 * kInset;
[super setFrame:frame];
}
-(void) drawRect:(CGRect)rect {
[self.layer setCornerRadius:kCornerRadius];
[self.layer setMasksToBounds:YES];
}
The constants are just any number for now, say 10
Next I ensure my UITableViewCell is pointing to this subclass.
Now my cells appear with a margin and the uitableview itself is 100% width.
I will have to keep playing around with it; maybe there is a better solution

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.

UIScrollView bounds have not yet resized in "viewDidLoad"

I have a UIViewController subclass whose view is configured in a NIB file. The view has a UIScrollView subview.
The UIScrollView takes up almost its entire NIB file but it's superview is added as a subview to a much smaller view (configured in a different NIB) - e.g. the UIScrollView is 80% the height of it's own NIB but ends up only being 10% the height of the application's window.
When I call [scrollView bounds].size.height in the viewController's viewDidLoad method, I get the height of the scrollView relative to it's own NIB, rather than the height it ends up resizing to as dictated by its superviews (e.g. 80% of the window's height rather than 10%).
If I call [scrollView bounds].size.height later on (e.g. to handle a rotation event), I get the correct value.
How can I get the correctly re-sized value initially?
Have you tried dealing with it in viewWillAppear: or viewDidAppear?
Assuming I'm following, there must be some point after the view controller is loaded at which you grab the .view and insert it into the other subview? If so then the bounds will be adjusted then. You can't get them in viewDidLoad because the view has no way of knowing what you'll do with it in the future. Even if your call to insert it as a subview is the very first thing you do after loading the view controller, it's the view accessor that'll cause the view to load and hence the viewDidLoad, all before you've actually put the view anywhere.
Since bounds has a getter and a setter, it should be key-value coding compliant, in which case you can use viewDidLoad to register an observer on bounds and do whatever it is you need to do when the bounds change.

Removing views from UIScrollView

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