在我的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;
}];
}
答案 0 :(得分: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];
}
答案 1 :(得分:0)
我最终拆分了我的创建方法并使用[[self.view subviews] containsObject:twitterLinksView]
来检查视图。另外值得注意的是,[self performSelector:@selector(createView) withObject:twitterLinksView afterDelay:0.76f]
必须略微领先于解雇动画才能使其完全正常工作......是的wtf。
我使用的didSelectRowAtIndexPath
方法[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];
}];
}