ios - Xcode 5.1,交换几个 UILabel 的位置

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

最佳答案

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

为什么要移动它?点的坐标没有变化。

关于ios - Xcode 5.1,交换几个 UILabel 的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24765680/

相关文章:

ios - 如何在加载数据后切换SpriteKit场景并确保GameCenter成功登录?

ios - ABAddressBookCopyPeopleWithName 在模拟器上返回空数组

ios - 如何在 UIAlertController 中使用 UITextView

objective-c - 自定义单元格标签不会自动换行

ios - 更改 UIView 的 alpha 会影响字体不透明度

iphone - iOS:使用 sizeWithFont:constrainedToSize:lineBreakMode 的 UILabel 动态高度:不起作用

ios - Swift 中的双线性插值

objective-c - tvOS:当按钮处于水平顺序时,将第一个按钮作为首选焦点 View

objective-c - 在应用程序开始添加教程

ios - 如何解决 "fatal error: module ' barcode_scan' not found”在codemagic中?