2015-09-27 96 views
0

如果更改標籤的文字,其容器會更改位置。 (自動佈局) 我簡單的代碼:更改文字,佈局更改

BOOL nextCard = [self loadCardInfo:card]; 

    if (nextCard == TRUE) { 

     [UIView animateWithDuration:0.3 animations:^{ 

      [card setFrame:CGRectMake(hideCardPosition.x, hideCardPosition.y, card.frame.size.width, card.frame.size.height)]; 

     }completion:^(BOOL complete){ 
     }]; 
} 

問題是在最後一行:

-(BOOL)loadCardInfo:(CardView*)card { 

if (dataArray.count > 0) { 

    card.string = [dataArray objectAtIndex:0]; 
    [dataArray removeObjectAtIndex:0]; 
    card.label.text = card.string; //THIS LINE 

    return YES; 

} else 

    return NO; 

} 

感謝

+0

請分享自動佈局。正確使用佈局約束可以使文本保持在固定位置。要實現這一點,應該看到Interface Builder屏幕很有用。 – nzs

+0

當然http://s27.postimg.org/dzspeozcj/image.png http://s22.postimg.org/xtf5b8nht/image.png –

+0

Thx,你也可以分享這個視圖的完全打開的樹層次結構,旁邊設計師在左邊 – nzs

回答

0

我不知道你想在+UIView animateWithDuration:animations:呼籲達到什麼但您可能不想將自動佈局與手動設置框架混合,就像您在animations塊中一樣。
最佳做法是(通常)堅持一個或另一個。
另外,也許你想要某種垂直自動佈局約束(固定到超級視圖或設置高度?)

+0

謝謝,但其他動畫的作品 –