Xcode 5.1,几个UILabel的交换位置

时间:2014-07-15 18:37:02

标签: ios objective-c uilabel

我正在使用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,但这也没有做任何事情。任何帮助,将不胜感激。谢谢!

1 个答案:

答案 0 :(得分:1)

CGPoint targetVisitGame1 = _homeGame1.center;
self.homeGame1.center = targetVisitGame1;

为什么要搬家?点的坐标没有变化。