0

これは、ボタンを押すことで UIView をフェードインおよびフェードしますが、このコードはより適切に記述できるようです。

- (IBAction)navigationTap:(id)sender {
if (navigationFolded == TRUE) {
    [UIView beginAnimations:@"MoveOut" context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    [UIView setAnimationDuration:0.2f];
    self.moveMe.frame = CGRectMake(0, 0, _moveMe.bounds.size.width, _moveMe.bounds.size.height);
    [UIView commitAnimations];
    navigationFolded = FALSE;
} else {
    [UIView beginAnimations:@"MoveIn" context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    [UIView setAnimationDuration:0.2f];
    self.moveMe.frame = CGRectMake(50-_moveMe.bounds.size.width, 0, _moveMe.bounds.size.width, _moveMe.bounds.size.height);
    [UIView commitAnimations];
    navigationFolded = TRUE;
}
4

2 に答える 2

1

コードに基づいてUIView、画面の横からスライドさせたいようです。フェードにはalphaUIView

アニメーションを実行するための新しいブロック ベースの構文を使用し、if ステートメントで x 位置の値だけをラップするだけでコードを簡素化できますnavigationFolded

- (IBAction)navigationTap:(id)sender {
    NSInteger xPos = 0;
    if (!navigationFolded) {
        xPos = 50-_moveMe.bounds.size.width
    }

    [UIView animateWithDuration:0.2f delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
        self.moveMe.frame = CGRectMake(xPos, 0, _moveMe.bounds.size.width, _moveMe.bounds.size.height);
    } completion:nil];

    navigationFolded = !navigationFolded;
}
于 2013-04-26T15:05:03.513 に答える
0

あなたが使用することができます:

- (IBAction)navigationTap:(id)sender {
if (navigationFolded == TRUE) {
    [UIView beginAnimations:@"MoveOut" context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    [UIView setAnimationDuration:0.2f];
    self.moveMe.alpha = 1;
    [UIView commitAnimations];
    navigationFolded = FALSE;
} else {
    [UIView beginAnimations:@"MoveIn" context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    [UIView setAnimationDuration:0.2f];
    self.moveMe.alpha = 0;
    [UIView commitAnimations];
    navigationFolded = TRUE;
}

(ケースが混同されている可能性があります-この場合、IFステートメントはUIViewを表示する必要があり、elseは徐々にフェードアウトします.YMMV)。

于 2013-04-26T14:55:58.677 に答える