0

I have a container view controller. It adds another controller as child view controller, and its view to view hierarchy.

So now I have:

UIView *self.view //main view
UIView *childView //child view controller's view

I also have UIImageView *imageView as child to childView. ImageView is pinned with constraints to its parent from left, right and top with some constant (12 points).

When I tap the button I slide the child view with the following code:

- (void)swipeDown:(UISwipeGestureRecognizer *)sender
{
    if (sender.state == UIGestureRecognizerStateRecognized && !self.menuOpened) {

        [UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{

            self.childView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 0, 120);

        } completion:^(BOOL finished) {

        }];
    }
}  

So the issue - right before the animation starts, the imageView moves its position up some amount. This can be countered by changing the constraint to some arbitary amount right before and after animation, but this is a dirty hack since it requires different values for different devices.

What it should look like and actually works on ios 8:

enter image description here

What it looks like on iOS 7 (the settings label is irrelevant, notice the position of image in relation to nav bar):

enter image description here

Again, on iOS 8 the transform works as it should, none of the subviews are moved. On iOS 7 subviews move out of control when view transform changes. How do I fix that?

Dvole
  • 5,725
  • 10
  • 54
  • 87
  • 1
    Well, `AutoLayout` does not work with `CGAffineTransform`. Have a look at this http://stackoverflow.com/questions/12943107/how-do-i-adjust-the-anchor-point-of-a-calayer-when-auto-layout-is-being-used/14105757#14105757 – Bartek Chlebek Oct 27 '14 at 14:02
  • @BartekChlebek Bartek could you make an answer please – Dvole Aug 26 '15 at 10:37

1 Answers1

1

Well, AutoLayout does not work with CGAffineTransform. Have a look at this How do I adjust the anchor point of a CALayer, when Auto Layout is being used?

Community
  • 1
  • 1
Bartek Chlebek
  • 1,665
  • 1
  • 16
  • 23
  • 1
    It works but not well. Indeed using a layer transform is better. I recommend you this link rather than the one proposed. http://www.apeth.com/iOSBook/ch14.html#_autolayout_and_view_transforms. – GaétanZ Aug 26 '15 at 12:00