2013-03-27 164 views
2

在我的didSelectRowAtIndexPath方法中,当用户选择一个单元格以便在视图已经被呈现时消除该视图时,我呼叫[self dismissView];。这显然不是非常优化的,并且它不覆盖presentView方法,而没有动画dismissView。有一个更好的方法吗?或者至少让它等待视图完成动画而不使用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; 
    }]; 
} 
+0

动画结束时可能跟踪? http://stackoverflow.com/questions/10612389/what-is-the-best-way-to-wait-for-a-loop-of-uiview-animations-to-finish – 2013-03-27 20:58:53

+0

不能说我发现这篇文章有帮助 – justMike 2013-03-27 21:45:51

回答

0

我结束了分裂出我的创作方法和使用[[self.view subviews] containsObject:twitterLinksView]来检查视图。另外值得注意的是[self performSelector:@selector(createView) withObject:twitterLinksView afterDelay:0.76f]必须在解散动画之前稍微超前,以便它可以在所有工作中... yeah wtf。

didSelectRowAtIndexPath方法I中使用[self performSelector:@selector(presentView:)];

由于甲基解决难题的一部分。

- (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]; 
    }]; 
} 
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动画一前一后。这个代码(内部块块),使该

这部分是编辑后: 现在OK,你可以尝试写这样的

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

// Do xyz... 

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

//[self presentView:twitterLinksView]; 
} 
+0

没有严格的说。作为第一次选择单元格并且视图被动画化。第二次选择单元格时,视图需要动画并用新数据重新生成动画。 – justMike 2013-03-27 22:00:28

+0

好的。为你的第二个选项(首先动画再次),你可以使用这个块。先动画页面,然后重新制作动画。对于第一个,一个块就足够了,除非我明白错误 – meth 2013-03-27 22:11:39

+0

根据代码它应该独立行动的两个独立的行为,一个不遵循另一个。 – justMike 2013-03-27 23:21:38