我使用的是 Xcode 5.1,我有几个 UILabel 需要交换位置。我关闭了自动布局。我需要这些标签在滑动手势期间交换位置。我已经交换了两个 UIContainer 对象的位置,您会在代码中看到这一点,我需要标签与容器一起移动。这是我的代码:
- (IBAction)handleSwipe:(UISwipeGestureRecognizer *)recognizer
{
//Get the center of each view container
CGPoint targetHomeCenter = _vistingTeamContainer.center;
CGPoint targetVisitorCenter = _homeTeamContainer.center;
CGPoint targetHomeNameCenter = _visitingTeamName.center;
CGPoint targetVisitorNameCenter = _homeTeamName.center;
//Get the center of each past score label
CGPoint targetHomeGame1 = self.visitGame1.center;
CGPoint targetHomeGame2 = self.visitGame2.center;
CGPoint targetHomeGame3 = self.visitGame3.center;
CGPoint targetVisitGame1 = self.homeGame1.center;
CGPoint targetVisitGame2 = self.homeGame2.center;
CGPoint targetVisitGame3 = self.homeGame3.center;
//Create the animation and swap positions of the controllers
[UIView animateWithDuration:0.7f
delay:0.0f
usingSpringWithDamping:0.7f
initialSpringVelocity:0.5f
options:UIViewAnimationOptionCurveEaseInOut
animations:^(){
//Move the containers
_homeTeamContainer.center = targetHomeCenter;
_homeTeamName.center = targetHomeNameCenter;
_vistingTeamContainer.center = targetVisitorCenter;
_visitingTeamName.center = targetVisitorNameCenter;
//Now move the past scores
self.homeGame1.center = targetVisitGame1;
self.homeGame2.center = targetVisitGame2;
self.homeGame3.center = targetVisitGame3;
self.visitGame1.center = targetHomeGame1;
self.visitGame2.center = targetHomeGame2;
self.visitGame3.center = targetHomeGame3;
}
completion:NULL];
};
正如预期的那样,UIContainers 移动得很好。 UILabels 根本不动。
我也试过 CGPoint targetHomeGame1 = _visitGame1.center
但这也没有做任何事情。任何帮助,将不胜感激。谢谢!
最佳答案
CGPoint targetVisitGame1 = _homeGame1.center;
self.homeGame1.center = targetVisitGame1;
为什么要移动它?点的坐标没有变化。
关于ios - Xcode 5.1,交换几个 UILabel 的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24765680/