I have a slider with 96 slots and I need to moves slider step by step from 0 to 95 in 60 seconds. Should I use NSTimer with interval (60/96) and 96 repeats or there is a better solution for this?
Moving slider during a certain time
667 Views Asked by stalk At
2
There are 2 best solutions below
1
NANNAV
On
aTimer = [NSTimer timerWithTimeInterval:(1.0) target:self selector:@selector(timerFired:) userInfo:nil repeats:YES];
NSRunLoop *runner = [NSRunLoop currentRunLoop];
[runner addTimer:aTimer forMode: NSDefaultRunLoopMode];
- (void)timerFired:(NSTimer*)theTimer {
slider.maximumValue=totaltime;
if(slider.value ==totaltime)
{
[theTimer invalidate];
//terminate the loop
}
else
{
slider.value=slider.value+1;
}
}
//timer runs continuously run if condition is true
Related Questions in OBJECTIVE-C
- How do I customize NSOutlineView to have border color?
- UIWebView Screen Fitting Issue
- How to hide "Now playing url" in control center
- CloudKit: Preventing Duplicate Records
- Image and Text locations in UIButton
- setting OpenGL version in objective-C
- Setup code for xibs in iOS. -awakFromNb:
- realm db, get parent link of object
- CFBundleDocumentType is not working in myproject-Info.plist file
- UIPopoverPresentationController not rendering properly
- Using Storyboard Reference
- Pass Data between two view controllers using 'Delegation' : Objective-C
- Unexpected CALayer Vertical Flipping on 3D Rotation 'Bounce'
- Setting View orientation to portrait is ignored
- UITextField append / between dates while enforcing character limit
Related Questions in IOS
- Overlapping UICollectionView in storyboard
- Cannot pod spec lint because of undeclared type errors
- Is the transactionReceipt data present in dataWithContentsOfURL?
- UIWebView Screen Fitting Issue
- ZXingObjC encoding issues
- iOS: None of the valid provisioning profiles allowed the specific entitlements
- How to hide "Now playing url" in control center
- CloudKit: Preventing Duplicate Records
- Slow performance on ipad erasing image
- Swift code with multiple NSDateFormatter - optimization
- iOS 8.3 Safari crashes on input type=file
- TTTTimeIntervalFormatter always returns strings in English
- How do I add multiple in app purchases in Swift Spritekit?
- Setup code for xibs in iOS. -awakFromNb:
- iOS Voice Over only reads out the title of any alert views
Related Questions in NSTIMER
- NSTimer won't start (Swift)
- NSTimer start and call method every 2 seconds and stop after 3 minutes
- Using NSTimer is Swift causes 'deinit' not to call
- Spawning a Spritekit node at a random time
- Adding time to NSTimer
- UIView transitionWithView not working first time only
- NSTimer firing more than it should
- Swift / Xcode6: How to change when the UIButton functionality is called after clicking the button
- How to create an alarm clock app with swift?
- How do I run a function with a parameter every 5 seconds in Swift?
- Countdown with several decimal slots, using NSTimer in Swift
- iOS Objective-C: Strange BOOL behaviour
- NSTimer questions (closure, @objc, and etc.)
- NSTimer behavior in background (addTimer:, beginBackgroundTaskWithExpirationHandler:)
- performSelector is calling new in if loop
Related Questions in UISLIDER
- How do I Create a Default Slider Value Programmatically?
- Aligning a UILabel with the center of UISlider thumb image in Swift
- How to display Label and UI-Slider-Range in Single Line
- UIslider thumb image doesn't start from the beginning
- how to implement alphabetic scrollbar like in music player app ios /
- Create a thumbnail image for video at a current frame while sliding the player
- I need a UISlider with value on the handle
- I want my UISlider value to be sent to mysql database when button is clicked
- Convert String to Float to move UISlider
- How to use the same slider for different divs (combine 3 individual function to one function in jquery)
- Move UISlider automatically in Swift
- Can a JQuery slider work with a simple calculation function?
- How can I restrict iOS slider value to an integer?
- Why is the slider's minimumValueImage in iOS gets blurred?
- jQuery UI Slider - how to use multiple sliders in a page
Related Questions in NSTIMEINTERVAL
- How to turn NSString hexInterval into NSTimeInterval for date conversion
- In iOS, Why [[NSDate date]timeIntervalSince1970] is double internally? It should be long long though
- NSTimer giving inexact results
- using AVAudioplayerNode play at particular NSTimeInterval time
- Substracting 1 hour from a nstimeinterval value
- Objective-C Fastest Way to find Closest NSDate in NSArray
- Compare current time with two times-of-day strings
- Converting Date to milli seconds in ios
- Test whether current time of day is between two TimeIntervals
- Is a pointer used with a NSTimeInterval?
- creating formatted NSDate using NSDateFormatter or mktime
- NSTime create a timeInterval
- Subtract minutes from NSDate
- NStimeInterval property error
- NSTimer with error message?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
That's probably the best approach. The
NSTimershould behave fairly consistently at that interval, it only starts to get unreliable when calling it around every 1/10th second, or faster.However, a bit of explanation in case it doesn't quite behave as you'd hoped:
It won't be perfect because the
NSTimerdoesn't have it's tick event literally every interval. Rather, theNSTimeris at the mercy of it's thread's run-loop, which may not get around to calling your@selectormethod until a while after its interval has expired. Then combine that with calling for screen updates which are also not lock-step.It's accuracy will mostly depend on what else you're doing in your run-loop... if there's not much going on in your device's little brain, then your slider should appear to move just as you'd hoped.
Edit: You may also consider an NSTimer with a longer interval, and use the UIView's animateWithDuration... methods to make it appear smooth?