Spin rate of UIActivityIndicatorView - ios

What is the spin speed of a UIActivityIndicatorView? Specifically, how long does it take to complete one revolution?
UPDATE: the reason for asking this is that I want to create my own activity indicator spinner that's smaller than the normal one. But I can't change the size of the normal one, so I'm making my own via UIImageView's animation options. I want to be as close to the normal one in behavior, timing, feel, etc. as I can get.

The spin rate of the UIActivityIndicatorView is 1.0 as of iOS 6.1.4. This number is an implementation detail and is not guaranteed to remain at this value for future versions of iOS. You can figure this out by accessing the first subview of a UIActivityIndicatorView, which is a UIImageView, and querying its animationDuration property. It looks like UIActivityIndicatorView uses an animated UIImageView under the hood.

Related

Dynamically enable/disable FXBlurView

I have an app where I blur the navigationbar and tabbar. Here I use FXBlurView to easily do this. I have noticed that the blur keeps being refreshed even though the view doesn't change. This causes the battery to drain quicker than I would want.
Is there a way to quickly detect if the view has changed, without having to take a snapshot (which also is +-5ms each time)?
You can use UIScrollViewDelegate methods for scroll changes and easily set dynamic property to true/false
As another option you can change updateInterval to a bigger value to provide delayed refreshes.

iOS - limit on UIView animate?

So I'm making a simple trivia game and I have a timerView that shrinks as time passes. When the user selects an answer, it needs to stop shrinking immediately - it must be very responsive. I give the user 10 seconds per question. Originally I would animate 10 times (with a duration of 1.0f), calling the next "segment" of animation in the completion block of the previous animation. In the completion block I would check to see if the user has tapped an answer, and if so I don't continue the chain. That solution works fine except that it's not very responsive because it's on a per second basis-- user taps an answer at the start of the second segment and the bar has a noticeable continuation.
My solution to THAT problem was to instead have 1000 animation calls with a duration of 0.01f. After doing that, the responsiveness was on point - the view stops animating as soon as I tap an answer -- the issue though, is that it's not actually 10 seconds, it takes more like 20.
So question number 1: what's the smallest time interval animateWithDuration can actually process properly?
Question number 2: is there a better way to accomplish what I'm trying to do accomplish?
ill answer question two: yes there definitely is a better way, have a look at CADisplayLink
use it to shrink your view a little bit each frame, and end the display link when you need to
the most responsive way is: the user taps an answer, you response in the touch callback, remove animations. you can remove animations by CALayer's removeAllAnimations method
Another way to do it is to set the view to shrinking using a single animation with linear timing, and then set the speed of the view's layer to 0 to pause the animation. When you set the speed on the layer to 0 the animation pauses instantly.
This works because under the covers, UIView animation actually creates and installs CAAnimation objects on the view's layers. It's possible to pause and continue an in-flight UIView animation just like you can a CAAnimation.
I have a project called KeyframeViewAnimations (link) on github that allows you to pause, continue, or "scrub" UIView and CAAnimations back and forth with a slider. You could use that technique. The tricky bit will be figuring out how far along the animation is.

Making a UISlider move back and forth on its own

In my current project I've created an app that utilizes the position of the UISlider in relation to a target value displayed to the user. I've got full functionality however I'm now trying to spice it up a bit.
Is it possible to set the UISlider to move from (minimum through maximum) than (maximum through minimum) back and forth on its own when the user enters the app rather than having them drag it?
Thoughts:
Possibly use a looping sequence?
Not looking for someone to code this for me I quite enjoy that part. Just looking for guidance.
Further to the NSTimer answer, I wouldn't suggest using that, but CADisplayLink instead. Similar process, but instead of using NSTimer use CADisplayLink.
CADisplayLink synchronises with the screen refresh rate, so you can adjust the animation and slider value based on current frame, so the animation appears smooth.
http://patzearfoss.com/2011/09/02/more-cadisplaylink/
I think that in this case you would have to setup an NSTimer with a time that you wish per frame, separate out the action code within the slider into a routine that can be called by you, then within the timer action code, call your routine, and then set the slider position manually.
Look here for setting up an NSTimer
How do I use NSTimer?
The NSTimer will essentially allow you to setup any framerate you wish, AND keep it off of the MAIN thread.
UISlider has this method that allows you to programatically change the slider's value:
- (void)setValue:(float)value animated:(BOOL)animated
Be careful about using loops though, you don't want to block your main thread an make your app unresponsive.
Trumpetlick's answer provides good information on using an NSTimer, which should help you with this.

What's causing the delay in my segues?

One of my views freezes up for several seconds when I tap the back button.
In addition, when I tap on one of the items in this view, it shows a popup (custom, not a UIPopoverController). This popup appears quite fast, but when I "flip" the popup to see it's back side, the same long delay occurs.
I suspect the reason has something to do with the complexity of the view. As you can see in the screenshot below, it's a collection view, it has a background and some of the subviews are rotated (UIViewEdgeAntialiasing is on).
I used the Time Profiler in Instruments to figure out what's going on, but I'm stuck.
I don't see anything useful unless I deselect "Hide System Libraries":
If I look at the method names, I think they are related to auto layout. That suggests that it's trying to render something during the segue. But methods such as cellForItemAtIndexPath are not called.
There is also an iPhone version of this app where I don't experience this problem at all. It uses a tableview in stead of a collectionview. It also has a background and rotated pictures.
I took these measurements using the simulator; on my iPad Mini the situation is worse; it can take up to 20 seconds before the animation starts.
Update - Things I've tried thanks to your answers:
turn off UIViewEdgeAntialiasing : no effect on performance
I think this might be due to the UIViewEdgeAntialiasing flag. It seems that your main view (the one with lots of slightly rotated pictures) have lots of antialiased edges and hence is very taxing on the iPad's GPU. The fact that the drawing performance slows down when your popover is spinning (ie when the background is showing again) gives this some credence.
Try turning it off and see if the performance improves. How does it look like?
Rotation was the bad guy here. Each UICollectionViewCell has a UIView as a container view and within that is a UIImageView. I rotate it like this:
container.transform = CGAffineTransformMakeRotation(M_PI * someRandomFloat);
Remove that line and everything is snappy.
I use the same technique on the iPhone, but apparently this kind of rotation has less of a performance impact in UITableViewCell than in UICollectionViewCell.
I tried subclassing UICollectionViewFlowLayout to rotate cell itself in stead of one subview. Unfortunately that causes a similar performance issue.

ios custom progress bar designing

I want to create a custom progress bar for my app. I am new to iOS development and finding it difficult to understand codes on google which confuse me a lot. What I want is like growing animated progress bar.
e.g: like showing progress in terms of a tree growth from small plant(to a complete tree) which denotes the process completion.
Where and how to start? And also is Core Graphics or cocos2d which one will be apt for this?
If you're doing something graphical like a tree growing, do you already have the animation you want to use as a series of images?
If so, you could use a UIImageView. Whenever you want to update your progress bar, just check the progress of your task, and use that to work out which number image to display. So if you had twelve images, you could find the percentage complete of your task, divide by 100 then multiply by twelve (and then convert to an int) to get the image number you want.
Once you've done that, just get the appropriately named image and put it in your image view:
self.myImageView.image = [UIImage imageNamed:[NSString stringWithFormat:#"frame-%i", myImageNumber]];
As for when to do the progress check, that depends on the task you are doing. Some tasks have a natural place to inject a callback to update the UI, and for others it's better to just use a timer.
you cannot change much in uiprogressbar instead you can use UISlide to behave like progressbar
.
you can only change the frame of progressbar as:-
UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle
:UIProgressViewStyleBar];
[progressView setFrame:CGRectMake(0,0,320,10)];
you can create a uiSlider and make its ThumbImage to nil,setMinimumTrackImage ans maxtrackImage and then use the custom function on it to show the progress
custom UISlider
https://github.com/jdg/MBProgressHUD
Try this code its modst widely used open source code for your kind of purpose

Resources