有趣而微妙的音符。如果视图已添加到 .xib 文件中,则视图是“弱”的,您需要使用临时变量进行交换。还有一些简单的数学运算可以让坐标与您在视图中设置的坐标相匹配:
@property (weak, nonatomic) IBOutlet UIImageView *imageView1;
@property (weak, nonatomic) IBOutlet UIImageView *imageView2;
CGRect tempFrame;
tempFrame = self.imageView1.frame;
CGRect tempFrame; // use bounds instead
tempFrame = self.imageView2.frame;
__strong UIImageView * tempView = self.imageView2;
[self.imageView2 willMoveToSuperview: nil];
[self.imageView2 removeFromSuperview];
[self.imageView2 willMoveToSuperview: self.imageView1];
[self.imageViewSkate addSubview: self.imageViewBall];
self.imageView2.frame = CGRectMake(tempFrame.origin.x - self.imageView1.frame.origin.x,
tempFrame.origin.y - self.imageView1.frame.origin.y,
tempFrame.size.width, tempFrame.size.height);
tempView = nil;