2
我遇到了UIView子视图动画的一些问题。我想要做的是,当你按下主视图时,子视图将从顶部滑下,然后在下一个水龙头上滑动并移除。但是在当前状态下,它只是执行第一次敲击命令,而在第二次敲击时,它会显示一个nslog,但视图和动画的删除不起作用。UIView动画无法正常工作
这里是事件处理函数的代码:
- (void)tapGestureHandler: (UITapGestureRecognizer *)recognizer
{
NSLog(@"tap");
CGRect frame = CGRectMake(0.0f, -41.0f, self.view.frame.size.width, 41.0f);
UIView *topBar = [[UIView alloc] initWithFrame:frame];
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"topbar.png"]];
topBar.backgroundColor = background;
if (topBarState == 0) {
[self.view addSubview:topBar];
[UIView animateWithDuration:0.5 animations:^{topBar.frame = CGRectMake(0.0f, 0.0f, self.view.frame.size.width, 41.0f);}];
topBarState = 1;
} else if (topBarState == 1){
[UIView animateWithDuration:0.5 animations:^{topBar.frame = CGRectMake(0.0f, -41.0f, self.view.frame.size.width, 41.0f);} completion:^(BOOL finished){[topBar removeFromSuperview];}];
NSLog(@"removed");
topBarState = 0;
}
}
我如何让这个子视图生命和正常删除吗?
问候
FreeSirenety
感谢您的回答,使其完美工作! :) – FreeSirenety