CGRect setFrame lost original value on iOS 8.0

The following code works fine on iOS 7.1

UIView *superView = self.superview;
[self removeFromSuperview];
CGFloat rightMarginWidth = self.rightMarginWidth ? self.rightMarginWidth : defaultRightMarginWidth;
CGRect newFrame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width + rightMarginWidth, self.frame.size.height);
//assign a new frame
self.frame = newFrame;
[superView addSubview:self];

      

However, on iOS 8.0, let's assume newFrame is the source = (x = 30, y = 29) size = (width = 127, height = 34). After the assignment self.frame

, = (x = 0, y = 0) size = (width = 127, height = 34) began to occur.

Why is the value "origin" lost here?

+3


source to share


1 answer


If the view controller has autodetect constraints, you must add self.translatesAutoresizingMaskIntoConstraints = YES;



-1


source







All Articles