0

In my app I apply filters for the image. I want to add UIProgressView as it takes about couple of seconds to complete the editing. How to add a UIProgressView for such method and also update how many percent it is completed? I have gone through many examples for UIProgressView but they are for Http request and loading network data. How to implement that for custom method ?

Girish
  • 4,692
  • 4
  • 35
  • 55
Prerna chavan
  • 3,179
  • 7
  • 35
  • 77
  • There is a similar question. Please see if it's what you seek http://stackoverflow.com/questions/15200982/display-uiprogressbar-with-percentage-in-ios/15201465#15201465 – Anupdas Mar 04 '13 at 12:50
  • 1
    As you have probably seen in the examples , 'UIProgressView' works with your input. So you have to set the desired percentage. If you made the filters , you can increase the percentage after each operation. If you are using standard filters you cannot really know how much will it take to complete the operation . You can estimate based on the image size and device type but that would not be a good practice. The best solution in this case would be to show an activity indicator instead. Hope this helps. Cheers! – George Mar 04 '13 at 12:52

3 Answers3

2

I guess you need to use Operation Queue for this.

[NSThread detachNewThreadSelector:@selector(showProgressView:) toTarget:self withObject:nil];

This has worked for me I hope it works for you too.. Have a happy Coding.!!

Pratik Somaiya
  • 818
  • 7
  • 18
1

If you have control over how much of the editing is completed, like any delegate events you can update the progress just like network calls or others. Even if you don't have such events, you might be having some inner methods, which can give you a delta of the total progress happened.

Then you can have a method which takes in this delta, add it to existing progress.

- (void)updateProgress:(CGFloat)delta
{
    [self.progressView setProgress:self.progressView.progress+delta];
    self.progressLabel.text = [NSString stringWithFormat:@"Completed : %.0f",self.progressView.progress*100];
}
Anupdas
  • 10,211
  • 2
  • 35
  • 60
0

It's difficult to answer this without knowing what data you have available to you, but essentially, you need to have a method that gets called at a consistent periodic time interval until the image filter gets applied. A trick for doing this would be if you could come up with a time estimate for a filter and then just use an NSTimer to fire a method until that time is complete. Although if you could figure out an exact time for it to filter, that would obviously be preferable.

From there you need to set the progress of the progress view to that time over the amount of time total like so...

self.progressView.progress = (float) progress

Keep in mind though that the progress view is a percent, so you will need to store two values to compare (divide over each other) 1) the total amount of time 2) the total amount of time passed. You can just do this though by setting up a float progress in your user @interface.

AdamG
  • 3,718
  • 2
  • 18
  • 28