0
我使用一些簡單的UIAnimation屬性來顯示和隱藏UIView。這段代碼似乎第一次完美地工作。但之後,動畫效果並未被看到。有沒有什麼即時通訊在這段代碼做錯了..我張貼我的代碼在這裏..請糾正我,如果我的代碼是不正確的,請建議我一個正確的做法。謝謝。UIAnimation似乎不能有效地工作
-(IBAction)animateSingleTap:(UIButton*)sender{
NSLog(@"trying to animate singletap");
if(singleTapViewIsShowing==NO){
[searchController hideSelf];
[singleTapView sendSubviewToBack:hideSingleTapButton ];
hideSingleTapButton.frame=CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[UIView beginAnimations:@"single tap animation" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationTransition:UIViewAnimationCurveEaseInOut forView:singleTapView cache:YES];
[self.view addSubview:singleTapView];
hideSingleTapButton.frame=CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[self.view bringSubviewToFront:singleTapView];
optionsButton.selected=YES;
singleTapViewIsShowing=YES;
singleTapView.frame=CGRectMake(sender.frame.origin.x-95, sender.frame.origin.y+30, singleTapView.frame.size.width, singleTapView.frame.size.height);
[UIView commitAnimations];
}
else {
[UIView beginAnimations:@"single tap animation" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView setAnimationTransition:UIViewAnimationCurveEaseInOut forView:singleTapView cache:YES];
[singleTapView removeFromSuperview];
optionsButton.selected=NO;
[UIView commitAnimations];
singleTapViewIsShowing=NO;
}
}
@ mmccomb:thanku for ur answer bro ..我編輯了我的代碼併發布了完整的代碼片段..事實上,我在設置singleTapViewIsShowing = NO ...請查看我的代碼...我已經通過在這個方法中加入了一些斷點來檢查我的代碼..控件在這裏輸入,但是動畫效果沒有被看到...... – 2011-03-12 13:08:28
嘗試更改'[UIView setAnimationTransition:UIViewAnimationCurveEaseInOut forView:singleTapView cache:YES];'to '[UIView setAnimationTransition:UIViewAnimationCurveEaseInOut forView:self.view cache:YES];'在這兩個動畫塊中 – mmccomb 2011-03-12 16:32:23
@ mmccomb:hey bro ..我在這裏改變了我的策略......我決定在代碼片段中使用alpha屬性它爲我工作。我設置singleTapView.alpha = 1,然後將其更改回0,它爲我工作。感謝您的幫助。乾杯... – 2011-03-13 13:13:01