我有一個UIScrollView子類,我用UIView動畫編程滾動。UIScrollView觸發事件期間動畫不animateWithDuration射擊:但工作正常與UIView beginAnimations:
我希望用戶能夠點擊或放大Scroll View的UIImageView內容,而動畫正在發生。
- (void) scrollSmoothlyatPixelsPerSecond:(float)thePixelsPerSecond {
// distance in pixels/speed in pixels per second
float animationDuration = _scrollView.contentSize.width/thePixelsPerSecond;
[UIView beginAnimations:@"scrollAnimation" context:nil];
[UIView setAnimationCurve: UIViewAnimationCurveLinear];
[UIView setAnimationDuration:animationDuration];
_scrollView.contentOffset = CGPointMake(_scrollView.contentSize.width, 0);
[UIView commitAnimations];
}
現在,由於iOS的4.0,UIView的beginAnimations:不鼓勵
這在使用類似於此的配方一直很好。所以我嘗試使用塊和UIView animateWithDuration更新我的代碼:滾動的工作方式與上述相同。
的關鍵和令人發狂的區別是,動畫的過程中,UIScrollView的和其他的觀點沒有更長的時間事件處理方法作出迴應:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
也不:
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView;
在嘗試時調用放大。
編輯爲了清楚起見:沒有UIView禮物響應觸摸事件。這不僅限於UIScrollView。 UIScrollView的對等UIToolbar不響應觸摸事件,也不響應UIScrollView的對等子視圖。看起來整個父級UIView被凍結在用戶交互之外,而動畫正在進行。再次,動畫完成後,所有上面的UIViews都會再次響應。
這些都是在UIView beginAnimations:中調用的,不管動畫狀態如何。
我的animateWithDuration:代碼稍有不同 - 但差異不重要。一旦動畫完成,上面的觸摸事件再次呼籲......
這裏是我的動畫代碼:
- (void) scrollSmoothlyToSyncPoint:(SyncPoint *) theSyncPoint andContinue:(BOOL)theContinueFlag{
float animationDuration = theSyncPoint.time - [player currentTime];
[UIView animateWithDuration:animationDuration
delay:0
options:UIViewAnimationOptionCurveLinear
animations:^{
[_scrollView setContentOffset:theSyncPoint.contentOffset];
}
completion:^(BOOL finished){
if (theContinueFlag) {
SyncPoint *aSyncPoint = [self nextSyncPoint];
if (aSyncPoint) {
[self scrollSmoothlyToSyncPoint:aSyncPoint andContinue:YES];
}
}
}];
}
唯一的事件處理程序,上面的動畫塊中的火災是:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event;
所以,問題:我應該 - 忽視蘋果的氣餒標籤,並繼續使用beginAnimation配方?我應該 - 使用hitTest重新實現縮放和其他基於觸摸的事件嗎?是否有一些關於動畫塊之間實現差異的知識可以幫助我解決這個問題?有什麼明顯的我失蹤了?
我是蘋果的一位新開發者,所以我不知道如何認真對待阻止標籤。但是,如果這個API將被棄用,然後消失,我寧願移動一個持久的方向。
非常感謝您的關注。
這種情況真的會出現由低內存情況進行提示。我沒有時間全面測試這是否確實是原因(這就是爲什麼我還沒有回答這個問題)。但是,在低內存情況下遇到類似的事件處理暫停之後,它確實會出現這種情況。現在 - 爲什麼基於塊的動畫會受到影響,而另一個則不會......當我得到時間和帖子時,我會運行一個全面的測試。 – Jackifus 2010-09-29 19:32:57