1

Below is my screen design.

enter image description here.

I want Zoom in/out in **mainView**. mainView Width & Height is 300. To Zoom in/out i have implement the below method and its working fine with this.

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return mainView;
}

Everything is fine up to this. I have set scroll.minimumZoomScale=1 and scroll.maximumZoomScale=5.

During Zoom in time mainView Frame increase depend on **scrollView.zoomScale**and i have check - (void)scrollViewDidZoom:(UIScrollView *)scrollView in this method.

At Zoom in time

**if i get scrollView.zoomScale=2 than mainView Width & height become 600
if i get scrollView.zoomScale=3 than mainView Width & height become 900**

During this process innerView resize due to autoresize property.But Width & Height of innerView is 100 (not change at zoom in/out time).

Can we change this according to scale ??

Finally what i want that Whenever innerView & lblTest frame change than i want to increase/decrease the numberOfLine of lblTest at zoom in/outtime.

I have tried to add innerView & lblTest manually but getting the issue that its Width & Height increase more than its superview (mainView).

Really appreciated If any know how to archive this .

Thanks in Advance.

Maulik
  • 19,348
  • 14
  • 82
  • 137
Hitarth
  • 1,950
  • 3
  • 27
  • 52

1 Answers1

4

When you are zooming in the scroll view, the zoomView (mainView in your case) is not resized, just an affine transformation applied on it's layer (CALayer). For example in case of 1.2 zoomScale it is :[1.2, 0, 0, 1.2, 0, 0]. So it's bounds is not changed - just all of it's content scaled up/down, it also affects it's frame property - so nor the contained inner view, and label will be resized, just scaled up/down when rendering the mainView, this is why their frame is unaffected.

Just implement - (void)scrollViewDidZoom:(UIScrollView *)scrollView in the delegate and print out the main view's frame, bounds, layer.affineTransform to see what happens on zooming.

To make what you want you have to adjust the label according the zoomScale:

- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
    float zoomScale = scrollView.zoomScale;
    self.label.bounds = CGRectMake(0, 0, 100*zoomScale, 100*zoomScale); // supposing that label's original size is {100, 100}
    self.label.layer.affineTransform = CGAffineTransformMakeScale(1.0/zoomScale, 1.0/zoomScale);
}
imihaly
  • 1,838
  • 13
  • 11
  • Thnaks. Your suggetion will really helpful for me. But in lable looks blur at zoom time. Before this its looks nice using lbl.contentScaleFactor = zoomScale; property . i Have set lbl.layer.contentsScale = scale; as per your suggestion but not working. what should i have to do for this ? – Hitarth Nov 11 '13 at 07:37
  • Setting `lbl.contentScaleFactor = 2` seems to solve the bluring issue. Tested on iPad2, iOS 7.0 – imihaly Nov 11 '13 at 08:00
  • yes text not blur in device. Due to affineTransform when i zoom in out 10 to 15 time i am getting "Receive memory warning" and than App crash + iPad crash (restarting) automatically. – Hitarth Nov 11 '13 at 08:27
  • Hm, strange. I don't think that the affine transformation is the cause of the memory warning. You should check it using Instruments. – imihaly Nov 11 '13 at 08:37
  • without affine transformation its working fine without crash. – Hitarth Nov 11 '13 at 09:43
  • 1
    can we continue this conversation in chat If you dont mind ?? – Hitarth Nov 11 '13 at 09:46
  • I did check it with instruments and there is no leak. Due the resize of the label of course when you zoom in there is an increased memory footprint, zooming in with factor 5 and with content scale 2 means that a 1000x1000 bitmap is allocated for it but I don't think that it itself is enough to get memory warning. You should check with Instrument all your allocations and check if there is a leak somewhere. Finally, you can optimize a bit using a threshold and resizing the label only if the change in zoomFactor is higher than that threshold. – imihaly Nov 11 '13 at 09:52
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/40940/discussion-between-coder-and-imihaly) – Hitarth Nov 11 '13 at 09:52
  • Thanks i appreciated to you. I have modify some code and i am done with this(without your suggestion i cant do this in short time).Finally i have set innerView with border but at zoom in time innerView border width also increase. So how can i stop this ?? is there any way to redraw the border in scrollViewDidEndZooming ?? – Hitarth Nov 12 '13 at 11:08
  • You can set `innerView.layer.borderWidth = 1.0/zoomScale` both in `scrollViewDidZoom` and `scrollViewDidEndZooming`. – imihaly Nov 12 '13 at 11:22
  • I have implemented something very similar on my `scrollViewDidZoom` using `CGAffineTransformMakeScale` on about 20 `UIImageView`s with `UILabel` subviews. Performance while `scrollViewDidZoom` is called is extremely poor --- would you have any idea why? – Michael J Petrie Jun 30 '14 at 00:54