[英]How to not interrupt each scrollView and NSTimer execute programmatically?
Scrollview和NSTimer的滾動受主線程影響,因此我無法同時處理兩個任務。
當特定時間發生滾動時,如何以編程方式處理兩個任務(NSTimer,滾動)?
MyView添加一個Scrollview,並在同一時間每秒鍾執行一次NSTimer動畫。
但是,滾動時,NSTimer不能播放動畫。 作品在Scrolling(稱為scrollViewDidEndDecelerating)結束時處於暫掛狀態(它們在Queue中等待)。
滾動時,我想同時使用NSTimer。
您沒有提供任何代碼,所以我將以一種方式將您的任務分成兩個不同的線程。
要移動動畫使其在后台線程中運行,以免動畫被中斷,請使用:
[self performSelectorInBackground:@selector(METHOD_NAME) withObject:nil];
例:
-(void)doStuff{
//Whatever you call here will be executed on main thread.
NSLog(@"This is main thread");
[self performSelectorInBackground:@selector(animate) withObject:nil];
}
-(void)animate{
//Whatever you call here will be executed on a background thread.
NSLog(@"This is background thread");
}
不要過度使用線程,它們會占用大量資源。 必要時使用它們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.