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