当我旋转图像时,它会向右移动。它不应该。似乎中心设置到了错误的点。见截图:在两种状态下——旋转而不是旋转——“+”的中心不应该改变。
我正在使用这样的自动布局定位 UIImageView:
- (void)viewDidLoad {
...
addIconImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"AddCardIcon.png"]];
[addIconImageView setContentMode:UIViewContentModeCenter];
[addIconImageView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.view addSubview:addIconImageView];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[addIconImageView]-(10)-|"
options:nil
metrics:nil
views:NSDictionaryOfVariableBindings(addIconImageView)]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat: @"V:|-[addIconImageView]-|"
options:NSLayoutFormatAlignAllCenterY
metrics:nil
views:NSDictionaryOfVariableBindings(addIconImageView)]];
...
}
这就是我旋转图像的方法
[UIView animateWithDuration:0.2
animations:^{
addIconImageView.transform = CGAffineTransformRotate(addIconImageView.transform, M_PI/4);
} completion:^(BOOL finished) {
}
];
轮换如何正确移动,我该如何避免?