简体   繁体   中英

UIView is resets to initial value after presenting other view controller

UIView's frame and position properties reset to initial value after presenting other view controller.

- (IBAction)moveClicked:(UIButton *)sender {
    self.imvOriginal.center = CGPointMake(self.imvOriginal.center.x + 200, self.imvOriginal.center.y + 200);
}

- (IBAction)showClicked:(UIButton *)sender {
    UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    TopViewController *vc  = [storyboard instantiateViewControllerWithIdentifier:@"topViewController"];
    [self presentViewController:vc animated:YES completion:nil];
}

After topViewController is closed, imvOriginal's center property is reset automatically. In fact, this properties is reset when topViewController is opened.

I will not use auto constraints, because I should implement move, scale, rotate of ImageView using Pan, Pinch, Rotate gestures. This features change the position, affineTransform properties of ImageView's layer.

How should I fix this problem?

Th problem you're seeing is caused by auto layout. Even if you don't set constraints for a view, if auto layout is on (which it is by default), the system will add constraints for you. If you want to use auto layout for some of the views in your storyboard, but not for another particular view, then that view should be created in code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM