2

こんにちは、1行だけが機能していないコードがあります...

[UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
    [label setFrame:CGRectMake(0, 0, frame.size.width, kStandardLabelHeight)]; //working
    [self.currentLabel setFrame:CGRectOffset(self.currentLabel.frame, frame.size.width, 0)]; //not working 
    [self.currentLabel setAlpha:0.0f]; //working
} completion:^(BOOL finished) {
    [self.currentLabel removeFromSuperview];
    self.currentLabel = label;
}];

何が間違っているのか、アイデアが不足しています...

4

4 に答える 4

2

私が見つけたのは、「自動レイアウトを使用」をオフにすると、魔法のように機能するため、この問題は自動レイアウトに関連していることです。

検索後、私はこれを見つけました:

ビューに制約アウトレット マッピングを追加すると、setFrame を使用する代わりに、制約を更新するだけでうまくいきます。

以下は私の最終的な実装です (_topConstraint は、テーブル ビューの上部の垂直スペースの制約です)。

- (IBAction)switchButtonTouched:(id)sender
{
    if (_topConstraint.constant <= 0)
        _topConstraint.constant = _buttonView.frame.size.height;
    else
        _topConstraint.constant = 0;

    [_tableView setNeedsUpdateConstraints];
    [UIView animateWithDuration:0.5f animations:^(void){
        [_tableView layoutIfNeeded];
    } completion:^(BOOL finished){
    }];
}
于 2014-05-13T02:04:29.093 に答える
0

フレームはCGRect4 つのパラメータ (xPosition、yPosition、幅、高さ) を持つ必要があります。CGRectMakeセット枠に使用

self.currentLabel.frame = CGRectMake(100, 100, self.currentLabel.frame.size.width, self.currentLabel.frame.size.height)

アニメーションの長さを 0.3 秒に設定し、終了したらビューから削除します。これは短すぎです。例 2 の期間を設定すると、ラベルが動いていることがわかります。

于 2013-09-22T17:32:59.453 に答える
0

アニメーションの後でもビューをアニメーション化するためのフレームを設定する必要がある場合があります。たとえば、完了ブロックで、そのようなことを試してください。

[UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
    [label setFrame:CGRectMake(0, 0, frame.size.width, kStandardLabelHeight)]; //working
    [self.currentLabel setFrame:CGRectOffset(self.currentLabel.frame, frame.size.width, 0)]; //not working 
    [self.currentLabel setAlpha:0.0f]; //working
} completion:^(BOOL finished) {
    self.frame = currentLabelFrame;
    label.frame = label.frame;
    [self.currentLabel removeFromSuperview];
    self.currentLabel = label;
}];
于 2013-12-06T09:41:00.850 に答える