久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

發(fā)生 uiscrollview 事件時未觸發(fā) NSTimer

NSTimer not fired when uiscrollview event occurs(發(fā)生 uiscrollview 事件時未觸發(fā) NSTimer)
本文介紹了發(fā)生 uiscrollview 事件時未觸發(fā) NSTimer的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個 UIImageView 放置在 UIScrollView 中,基本上這個 UIImageView 擁有非常大的地圖,并在帶有箭頭"指向導航方向的預定義路徑上創(chuàng)建動畫.

I have a UIImageView placed in UIScrollView, Basicly this UIImageView holds very big map, and created animation on a predefined path with "arrows" pointed navigation direction.

但是,每當發(fā)生 uiscrollevents 時,我認為 MainLoop 會凍結并且 NSTimer 不會被觸發(fā),并且動畫會停止.

But, whenever uiscrollevents occurs, I think MainLoop freezes and NSTimer being not fired, and animation stopped.

在 UIScrollView、CAKeyFrameAnimation 或 NSTimer 上是否存在解決此問題的任何現有屬性?

Are there any existing property, which solves this problem, on UIScrollView, CAKeyFrameAnimation or NSTimer?

//viewDidLoad
   self.myTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(drawLines:) userInfo:nil repeats:YES];

- (void)drawLines:(NSTimer *)timer {

   CALayer *arrow = [CALayer layer];
   arrow.bounds = CGRectMake(0, 0, 5, 5);
   arrow.position = CGPointMake(line.x1, line.y1);
   arrow.contents = (id)([UIImage imageNamed:@"arrow.png"].CGImage);

   [self.contentView.layer addSublayer:arrow];

   CAKeyframeAnimation* animation = [CAKeyframeAnimation animation];
   animation.path = path;
   animation.duration = 1.0;
   animation.rotationMode = kCAAnimationRotateAuto; // object auto rotates to follow the path
   animation.repeatCount = 1;
   animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
   animation.fillMode = kCAFillModeForwards;

   [arrow addAnimation:animation forKey:@"position"];
}

推薦答案

iOS 應用程序在 NSRunLoop 上運行.每個 NSRunLoop 對不同的任務都有不同的執(zhí)行模式.例如,默認的 nstimer 計劃在 NSRunLoop 上的 NSDefaultRunMode 下運行.然而,這意味著某些 UIEvents,scrollviewing 是一個,將中斷計時器,并將其放在隊列中,以便在事件停止更新時立即運行.在您的情況下,為了讓計時器不被中斷,您需要將其安排為不同的模式,即 NSRunLoopCommonModes,如下所示:

iOS Applications run on an NSRunLoop. Each NSRunLoop has different modes of execution for different tasks. For example, the default nstimer is scheduled to run under the NSDefaultRunMode on the NSRunLoop. What this means however is that certain UIEvents, scrollviewing being one, will interrupt the timer, and place it on a queue to be run as soon as the event stops updating. In your case, in order to get the timer to not be interrupted, you need to schedule it for a different mode, namely NSRunLoopCommonModes, like so:

  self.myTimer =  [NSTimer scheduledTimerWithTimeInterval:280
                                                                 target:self
                                                               selector:@selector(doStuff)
                                                               userInfo:nil
                                                                repeats:NO];
  [[NSRunLoop currentRunLoop] addTimer:self.myTimer forMode:NSRunLoopCommonModes]; 

此模式將允許您的計時器不會被滾動打斷.您可以在此處找到有關此信息的更多信息:https://developer.apple.com/documentation/foundation/nsrunloop在底部,您將看到可以選擇的模式的定義.還有,傳說有,你可以編寫自己的自定義模式,但恐怕很少有人能活著講述這個故事.

This mode will allow your timer to not be interrupted by scrolling. You can find more about this info here: https://developer.apple.com/documentation/foundation/nsrunloop At the bottom you will see the definitions of the modes you can choose from. Also, legend has it, you can write your own custom modes, but few have ever lived to tell the tale im afraid.

這篇關于發(fā)生 uiscrollview 事件時未觸發(fā) NSTimer的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯(lián)網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

相關文檔推薦

How to subclass UIScrollView and make the delegate property private(如何繼承 UIScrollView 并使委托屬性私有)
Swift - how to get last taken 3 photos from photo library?(Swift - 如何從照片庫中獲取最后拍攝的 3 張照片?)
Setting contentOffset programmatically triggers scrollViewDidScroll(以編程方式設置 contentOffset 觸發(fā) scrollViewDidScroll)
Photos app-like gap between pages in UIScrollView with pagingEnabled(使用 pagingEnabled 的 UIScrollView 中頁面之間的照片應用程序式間隙)
why UIScrollView is leaving space from top in ios 6 and ios 7(為什么 UIScrollView 在 ios 6 和 ios 7 中從頂部留下空間)
UIScrollView pauses NSTimer while scrolling(UIScrollView 在滾動時暫停 NSTimer)
主站蜘蛛池模板: 91麻豆精品国产91久久久更新资源速度超快 | 国产精品国产三级国产播12软件 | 一区二区在线免费观看 | 精品久久久久久久 | 日韩久久久一区二区 | 久久天堂网 | 成人免费看片 | 日韩不卡一二区 | 欧美福利影院 | 久久久精品一区二区 | 91超碰caoporn97人人 | www.亚洲一区二区三区 | 国产精品久久久久久久免费观看 | 在线中文视频 | 亚洲三区在线观看 | 中文字幕日韩一区 | 国产综合在线视频 | 黄色网址大全在线观看 | 羞羞视频在线观看 | 99精品免费久久久久久久久日本 | 精品久久久久久久久久 | 91麻豆产精品久久久久久 | av黄色免费在线观看 | 亚洲精品99 | 欧美日韩亚洲三区 | 无人区国产成人久久三区 | 狠狠av| 国产99视频精品免费播放照片 | 九九亚洲| 国产精品一区二区久久 | 国产精品99久久久久久宅男 | 欧美精品导航 | 人人叉 | 免费看国产片在线观看 | av天天爽| 免费视频一区二区 | 超级乱淫av片免费播放 | 中文字幕在线人 | 日韩一区二区三区在线观看 | 日韩精品一区二区三区视频播放 | av片在线观看网站 |