Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What about scheduledtimerwithtimeinterval?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article will explain in detail what to do about scheduledtimerwithtimeinterval. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

With + scheduledTimerWithTimeInterval... When the timer is triggered by the way, timer will provisionally callback when you slide the list on the page. Why? How to solve?

What about scheduledtimerwithtimeinterval?

RunLoop can only run under one kind of mode. If you want to change the mode, the current loop needs to be stopped and restarted. Using this mechanism, the mode of NSDefaultRunLoopMode (kCFRunLoopDefaultMode) switches to UITrackingRunLoopMode during ScrollView scrolling to ensure smooth sliding of ScrollView: events that can only be handled in NSDefaultRunLoopMode mode affect the sliding of ScrollView.

If we add a NSTimer object to the main run loop as NSDefaultRunLoopMode (kCFRunLoopDefaultMode), the ScrollView scrolling process will no longer be scheduled because of the switching of mode.

And because mode is customizable, so:

The problem that Timer timing can be affected by scrollView sliding can be solved by adding timer to NSRunLoopCommonModes (kCFRunLoopCommonModes).

The scheduledtimerwithtimeinterval code is as follows:

/ / add timer to NSDefaultRunLoopMode

[NSTimerscheduledTimerWithTimeInterval:1.0

Target:self

Selector:@selector (timerTick:)

UserInfo:nil

Repeats:YES]

/ / and then add it to NSRunLoopCommonModes

NSTimer*timer= [NSTimertimerWithTimeInterval:1.0

Target:self

Selector:@selector (timerTick:)

UserInfo:nil

Repeats:YES]

[[NSRunLoopcurrentRunLoop] addTimer:timerforMode:NSRunLoopCommonModes]

This is the end of the article on "what to do with scheduledtimerwithtimeinterval". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report