2

私の方法では、既に表示されている場合にビューを閉じるために、ユーザーがセルを選択したときdidSelectRowAtIndexPathに呼び出します。[self dismissView];これは明らかにあまり最適ではなく、dismissView をアニメーション化せずに presentView メソッドをオーバーライドしています。これを行うより良い方法はありますか?または、少なくとも NSTimer を使用せずに、ビューのアニメーションが終了するのを待ちます。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
    [self dismissView];

// Do xyz...

[self presentView:twitterLinksView];

それで..

- (void)presentView:(id)sender
{
    twitterLinksView.frame = CGRectMake(0, (self.view.frame.size.height + viewHeight), 320, 300);


    [UIView animateWithDuration:0.60f animations:^{


        CGRect twitterLinkFrame   = self.twitterLinksView.frame;
        twitterLinkFrame.origin.y = (self.view.frame.size.height - viewHeight);

        twitterLinksView.frame = twitterLinkFrame;
    }];
}

- (void)dismissView
{

    [UIView animateWithDuration:0.75f animations:^{

        CGRect twitterLinkFrame   = self.twitterLinksView.frame;
        twitterLinkFrame.origin.y = (self.view.frame.size.height + viewHeight);

        self.twitterLinksView.frame = twitterLinkFrame;
    }];
}
4

2 に答える 2

1
[UIView animateWithDuration:1. animations:^{

     //firstAnimationBlock

    } completion:^(BOOL finished){
        [UIView animateWithDuration:1. animations:^{

//animations in this block will be called after firstAnimationBlock has expired
        }];
    }];

私が理解しているように、2つのアニメーションを次々に発射したいと思っています。このコード(ブロック内のブロック)はこれを行います

この部分は編集後です。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
    [self dismissView];

// Do xyz...

[self performSelector:@selector(presentView:) withObject:twitterLinksView afterDelay:0.75];

//[self presentView:twitterLinksView];
}
于 2013-03-27T21:43:11.387 に答える
0

私は自分の作成方法を分割し[[self.view subviews] containsObject:twitterLinksView]、ビューを確認するために使用しました。また、[self performSelector:@selector(createView) withObject:twitterLinksView afterDelay:0.76f]アニメーションを完全に機能させるには、アニメーションを閉じるよりもわずかに先行する必要があることに注意してください...ええ、wtf。

didSelectRowAtIndexPath私が使った方法では[self performSelector:@selector(presentView:)];

パズルの一部を解いてくれた meth に感謝します。

- (void)presentView:(id)sender
{

    if ([[self.view subviews] containsObject:twitterLinksView])
    {
        [self dismissView];
        [self performSelector:@selector(createView) withObject:twitterLinksView afterDelay:0.76f];
        NSLog(@"Animating ut old");

    }
    else
    {
        NSLog(@"Creating new view");
        [self createView];
    }
}
-(void)createView
{
    twitterLinksView.frame = CGRectMake(0, (self.view.frame.size.height + viewHeight), 320, 300);

    [UIView animateWithDuration:0.60f animations:^{

        CGRect twitterLinkFrame   = self.twitterLinksView.frame;
        twitterLinkFrame.origin.y = (self.view.frame.size.height - viewHeight);

        twitterLinksView.frame = twitterLinkFrame;
        [self.view addSubview:twitterLinksView];

    }];
}

- (void)dismissView
{

    [UIView animateWithDuration:0.75f animations:^{

        CGRect twitterLinkFrame   = self.twitterLinksView.frame;
        twitterLinkFrame.origin.y = (self.view.frame.size.height + viewHeight);

        self.twitterLinksView.frame = twitterLinkFrame;

    }completion:^(BOOL finished){
        [twitterLinksView removeFromSuperview];
    }];
}
于 2013-03-28T01:07:56.093 に答える