How to zoom on an UITextView inside a UIScrollView? - ios

I have a UIScrollView which contains instances of an UIView subclass.
This UIView has a CAShapeLayer as a sublayer of its layer, and a UITextView as a subview.
With zooming enabled on the UIScrollView, the CAShapeLayer remains sharp when I zoom, but the UITextView doesn't.
Is there a way to have the UITextView redraw at the correct resolution?

you can use [yourTextView contentScaleFactor] or [yourTextView.layer contentsScale]. Set it to the current scalefactor.

Related

How to zoom image without zooming subviews of an image? swift ios

I added UIImageView which is subview of UIScrollView. Then I added UIButton is subview of UIImageView. When I zoom UIImageView then UIButton is also perform zooming. I want only zoom UIImageView not UIButton. How can I achieve this?
Since UIButton is subview of UIImageView, it will pan/zoom when you zoom/pan UIImageView. To solve your problem, make it subview of some other view, perhaps UIScrollView in your case.

UIImage from UIView if UIView is outside window bounds

I have UIScrollView with many UIView views added to the content. I would like to convert UIView and its subviews to UIImage and I know how to do it if the UIView is currently visible on the device screen. Is it possible to convert UIView (subview in UIScrollView) into UIImage if UIView is not in UIScrollView visible rect?
Could you just iterate over all subviews taking a screenshot of each UIView inside the UIScrollView ?
The following class may help with taking screenshots:
http://ioscodesnippet.com/2011/08/25/rendering-any-uiviews-into-uiimage-in-one-line/
Hope you find a solution.
Thanks,
Michael

UITextView scrolling issue when image is added as a subview

I have a fixed size UITextView and if I add more word's, it will scroll to it's content. I'm adding an UIImage as a subview in UITextView. If there are more comment's I cannot scroll UITextView to see the image. Can we set the content height of uitextview to solve this issue?
UITextView is not designed to receive a subview like that, and it won't scroll it correctly. You need to add both as subviews in a UIScrollView, which should auto-behave like so:
Swiping should first scroll the view where the touchDown event began (i.e., your UITextView)
When that view has no more to scroll, the event should bubble up to the UIScrollView itself, bringing up your UIImage.
If you don't like this behavior then you can synchronize scrolling as you prefer by calculating the height of your text inside your UITextView bounds, using:
CGSize size = [myText sizeWithFont:myFont forWidth:myFontWidth.0 lineBreakMode:UILineBreakModeWordWrap];

Convert UIScrollView contentOffset and contentSize to layer position and bounds properties

I have a UIScrollView displayed in fullscreen holding a UIImageView that fills the contentView of the scrollView. I added a method to register the contentOffset and the contentSize of the scrollview at a specific pan and zoom.
I'm trying to convert those coordinates to a CALayer that I can animate using the position and bounds in order to animate a pan and zoom to the desired point.
How to convert the contentOffset and contentSize of a UIScrollView to a CALayer bounds and position properties. The CALayer is a screen sized CALayer and is add to another screen sized CALayer.
Looks like I just had to ask the question to finally answer my own problem!
set the anchorPoint of the CALayer to CGPointZero
then set the bounds size to the contentSize
set the position to the negative contentOffset {-contentOffset.x,-contentOffset.y}
Finally.

UIScrollView or UIImageView?

I need to place a photo in the screen and it should be able to be scrolled or zoomed,
I know UIScrollView does these, so I alloced one, but how about my photo?
I guess I should not just set the photo as the backgroundColor of my UIScrollView, and I haven't found any property of UIScrollView, in the document, to hold an image, such as "imageView", "contentView", or something like that.
So, what should I do to make a picture in my screen and make it able to respond to finger touches?
Thanks a lot!
Add the UIImageView to the UIScrollView and set the min/max scale value to it.
Then implement the following UIScrollViewDelegate function.
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return yourImageView;
}
If you want to have multiple items scaled, add all the view into a UIView, and put that UIView inside the UIScrollView. Of course you have to change the return view to that UIView in the above function.
Just add your UIImageView as a subview of the UIScrollView. Also, set the scroll view's contentSize property to be equal to the size of the image view's frame.
THe scrollView is the first step.
Then you should add a UIImageView and load an image inside.
You need also to set the max e min zoomScale properties of the scrollview
And you must implement the scrollview delegate method – viewForZoomingInScrollView:

Resources