Prerna chavan
Prerna chavan

Reputation: 3249

Use UIProgressView for image editing

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 ?

Upvotes: 0

Views: 169

Answers (3)

AdamG
AdamG

Reputation: 3718

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.

Upvotes: 0

Pratik Somaiya
Pratik Somaiya

Reputation: 833

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.!!

Upvotes: 2

Anupdas
Anupdas

Reputation: 10201

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];
}

Upvotes: 1

Related Questions