0

I am trying to Scale a UiView and its UIImageView subview using: CGAffineTransform original = mv.transform; CGAffineTransform new = CGAffineTransformScale(original, 2, 2);

But this results in the ImageView being way off from where it started:

Before the transofrm the imageview (the book) is at the center of the purple circle. This shows it after the transform(which is done in a spring animation block)

Before the transofrm the imageview (the book) is at the center of the purple circle. This shows it after the transform(which is done in a spring animation block)

For the record autolayout is off in IB

user2489946
  • 281
  • 3
  • 12
  • @Andy I did use autolayout to center the imageview but even if i remove the constraints before carrying out the transform the issue remains – user2489946 Nov 28 '14 at 23:31
  • I still believe it's autolayout messing with you. Have you considered using CALayer/CAShapeLayer? I know it's extra work to center them, but it worth a shot. I had similar behavior on autolayout until I turned it off with translatesAutosizingMaskTo... There is a quite comprehensive research on that here http://stackoverflow.com/questions/12943107/how-do-i-adjust-the-anchor-point-of-a-calayer-when-auto-layout-is-being-used?lq=1 – pronebird Nov 28 '14 at 23:35
  • I tried this with the subview being centered in the larger view with auto layout (centerX and centerY). It worked fine. Are you sure your "book" is a subview of the purple circle? – rdelmar Nov 28 '14 at 23:40
  • @Andy Yup, Its definitely autolayout. I didnt add any constraints and set the view by using its frame property and it worked just fine. – user2489946 Nov 29 '14 at 00:42
  • @rdelmar Did you also set the views height and width constraints when you set centerX and centerY contraints? I have added centerX, centerY and height and width constraints to the imageview. – user2489946 Nov 29 '14 at 00:43
  • Yes, I did. Both views had fixed height and width. – rdelmar Nov 29 '14 at 01:01

1 Answers1

1

So after tinkering with it for some hours, I was able produce the desired effect. I was also changing the center of the view in the animation block and I found that if I placed the statement assigning the center value before assigned the new transfrom, the subview stayed centered during the transform and center - change. Also, I found that if I was working with a UIView subclass, I had to make a call to layoutIfNeeded before the animation block on the view being scaled and moved. Interestingly enough, when working with regular UIView objects I found that it was not necessary to make the call to layoutIfNeeded in order to produce the desired effect of keeping the subview centered after the center cahnge and transform.

I am at a loss as to why these specific conditions are required to keep the subview centered during a transform and coordinate move. I've been looking through the Apple Documentation but have yet to find a sure explanation.

user2489946
  • 281
  • 3
  • 12