2

在我的didSelectRowAtIndexPath方法中,[self 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 回答