// 根据我的评论构建
在 c 部分中, tileView.frame=CGRectMake(targetView.frame.origin.x, targetView.frame.origin.y, 20, 20); 我会认为因为你在做 targetView.frame.origin.x, targetView.frame.origin.y 它只是把它从屏幕上移开。我认为它应该是 0, 0 作为您添加以查看您从中获取坐标的内容。
-(void)placeTile:(TileView*)tileView atTarget:(TargetView*)targetView {
[UIView animateWithDuration:0.35 delay:0.00 options:UIViewAnimationOptionCurveEaseOut animations:^{
[tileView removeFromSuperview];
tileView.frame=CGRectMake(targetView.frame.origin.x, targetView.frame.origin.y, 20, 20);
[targetView addSubview:tileView];
NSLog(@"%f,%f,%f,%f",tileView.frame.origin.x,tileView.frame.origin.y,tileView.frame.size.width,tileView.frame.size.height);
[tileView bringSubviewToFront:targetView];
}
completion:^(BOOL finished){
}];
请参阅您将 tileview 设置为具有与 targetView 相同的 x 和 y,但您添加到目标视图。我想你想把它放在 0,0 或者转换点。
[UIView animateWithDuration:0.35 delay:0.00 options:UIViewAnimationOptionCurveEaseOut
animations:^{
tileView.frame=CGRectMake(0, 0, 20, 20);
[targetView addSubview:tileView];
}
completion:^(BOOL finished){
}];
编辑:
iMobile 提出了一个很好的观点,来自苹果的文档说 addSubview 如果在添加之前已经有一个超级视图,那么 addSubview 会删除它。
"Views can have only one superview. If view already has a superview and that view is
not the receiver, this method removes the previous superview before making the
receiver its new superview."