After adding the second view, you have already set its transformation to CGAffineTransformMakeTranslation(-1000, 0) , and when you want to remove this view, you will install the exact same transformation, so it will have no effect. You have 2 options:
Apply the translation to a transformation that already has the form:
CGAffineTransform newTransform = CGAffineTransformConcat(rectangleView.transform, CGAffineTransformMakeTranslation(-1000, 0)); [rectangleView setTransform:newTransform];
Instead of applying transformations, directly work with the position of the view (for example, through its center property)
UIView *rectangleView = [detailView viewWithTag:4];
source share