Apple Watch cannot find Activity Indicator - ios

I am developing an Apple Watch application in which I am calling an API which takes some time to execute, so to show user process is going on I need to show Activity Indicator. I am trying hard to find the solution as there is no Activity Indicator included in Apple Watch. One solution is to take image and animate image when we start the process and hide when we get response but is there any better solution as we need to add multiple images?

Unfortunately, there is no activity indicator interface element in WatchKit. You can create your own using the technique you've described. That is, unhide and begin an animated image sequence while you're waiting for a response, and hide it when the operation is complete.
This is the exact same technique that I use in my own Watch app. In my case, I load 4 images, so there are 4 unique activity indicator images that "spin" while the images are retrieved.

Create custom Activity Indicator using WKInterfaceImage like this;
IBOutlet WKInterfaceImage *animatedImage;
Now add images in sequence for animation in WKInterfaceImage in Images.xcassets
The method for hiding and unhiding activity indicator :
-(void)showActivityIndicator:(BOOL)yesOrNo
{
if (yesOrNo)
{
//unhide
[self.animatedImage setHidden:NO];
// Uses images in WatchKit app bundle.
[self.animatedImage setImageNamed:#"ActInd"];
[self.animatedImage startAnimating];
}
else
{
[self.animatedImage stopAnimating];
//hide
[self.animatedImage setHidden:YES];
}
}

We can use WKInterfaceImage set Images spinner#2x1.png and then animate image using startAnimatingWithImagesInRange
Now add images in sequence for animation in WKInterfaceImage in Images.x cassets
spinner#2x1.png,spinner#2x2.png.....spinner#2x40.png
Then use following method
NSRange model = NSMakeRange(0, 40);
/* set Image to ImageView */
[self.spinnerImage setImageNamed:#"spinner#2x1.png"];
/* set repeat count 0 for continues rotation */
[self.spinnerImage startAnimatingWithImagesInRange:model
duration:1.0
repeatCount:0];
This method works but it not smooth and if need set in center of view, then image needs to hidden first then unhide and animate image while process is going on and again hide after we get response,and if their multiple view then it becomes hectic is there any way to add image above all views or create dynamic activity indicator so that we add any where we need

'WatchKithas no UI control likeActivityIndicator, but we can create custom activityIndicator with the help ofWKInterfaceImage`.
You can find more more detail on this stackoverflow-link.

Related

Xcode Display a loading view until the second view loads (on a segue show)

I have an app that switch views using a segue when a button is clicked.
The second view loads data from the internet and it can take a couple of seconds.
I would like to know how can i display a loading view/splash screen in the meantime so the view could finish the loading and the app wont appear like it's doing nothing.
Thanks!
Check this library SwiftSpinner. It serves the purpose of your needs. It's really brilliant.
Call the necessary function from the library in the viewDidLoad method of your ViewController which loads the data from the internet. Remove this view in DidFinishLoading method of the NSURLProtocol (It's an optional func declared in that class which detects when the request to that URL is complete). The documentation is given in that library itself.
Sounds like you're looking for an activity indicator. I've used the custom class posted https://stackoverflow.com/a/32661590/3516923 with success. Just a note of warning, in his class he blocks all input while the indicator is in view. If you want to make it so your users can back out before things finish you need to remove UIApplication.sharedApplication().beginIgnoringInteractionEvents() and UIApplication.sharedApplication().endIgnoringInteractionEvents() from the start and stop animating functions.
If what you want is really a splash screen, have a UIImageView underneath the view that you're loading. Set the image to your splash screen image. Set the loading view to hidden=YES before it's shown, then set hidden to NO after it finishes loading. You could even set the opacity of the frontmost view to give you a fading effect.
1.You need to find a kind of indicator, suck like an activity indicator or something else to show the loading UI to the user.
2.Set the user interaction unable, so that the user won`t touchup inside repeatedly.
3.Start the indicator, set the user interaction unable when you load the server data, and stop the indicator animation when you finish, hide the indicator, enabled the user interaction.

How to create a scrolling image gallery in iOS?

In my app, I have 5 images, and 2 buttons(next and previous).
I have stored those images in an array.
When next button is pressed, I want to remove the current image and display the next image, and for previous button, it is vice versa.
I have done this using the code.
-(void)nextButton:(id)sender
{
if (i < (array.count-1))
{
i=i+1;
imageView.image = [images objectAtIndex:i];
}
}
-(void)previousButton:(id)sender
{
if(i >= 1)
{
i=i-1;
imageView.image=[images objectAtIndex:i];
}
}
Now, my doubt is, when the image changes, there happens no animation, simple the next image replaces the previous image.
But, my request is when I click the button, the previous button should decrease by the width and move out of the imageView and the next image should come inside the imageView gradually like this
I understand it and it looks like you would need some custom animation, check out it has various animation and u can use anyone you like
Currently you are just simply assigning image to the imageview. that's why there is no animation. For this animation, you can use the below library
http://code4app.net/ios/iCarousel-for-Cover-Flow/4f87d2db06f6e79d32000000
I guess you need a cover flow effect. Try browsing iCarousel. Try link below, it provides great options for different style
https://www.cocoacontrols.com/controls/icarousel
use iCarousel .. in this you will have # 7 types of animation. if you don't want to use 3rd party code. Better option is fade-out current image and fade-in new image.

How to show a GIF on iOS in a certain frame, not show it until fully loaded, and allow zoom?

When a user selects a GIF, I want to present an overlay on top of everything showing the GIF.
I know there's a few ways on iOS to do this. There's the great UIImage+animatedGIF which works decently well, but for longer GIFs they're very slow and don't play back at the same speed as a UIWebView would (which plays at the accurate playback speed).
It sucks, because if that category didn't play them back slowly it would do everything I need.
But it doesn't, so I tried with UIWebView, however I'm confused about three things:
How do I get size that the UIWebView should be when presented (its frame)? Would I have to download the GIF first as a UIImage then check its size property? Is there a better way (might take awhile)?
How do I stop it from playing until it's fully loaded?
With the above category, as it's just a UIImage, when I embed it as a UIImageView in a scrollview it's very easy to zoom in and out of. Is this possible with a UIWebview?
1.
The first solution that comes to mind is to set the background of the webview to clear color and place it in the right location after it finishes loaded.
Usually I use
[webView stringByEvaluatingJavaScriptFromString:#"document.body.offsetHeight;"]
but that won't work if you are directing your webview to a gif url.
2.
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
webView.alpha = 1;
}
That way the UIWebView will be shown to the user only after the gif is full loaded.
3.
[webView setScalesPageToFit:YES];
You can use SDWebImage it has Animated GIF support
https://github.com/rs/SDWebImage/blob/master/SDWebImage/UIImage%2BGIF.m
_block BOOL flag = NO;
NSURL *imageURL = [NSURL URLWithString:#"ImageUrl" relativeToURL:#"mainURL"] ;
SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadWithURL:imageURL
options:0
progress:^(NSUInteger receivedSize, long long expectedSize)
{
}
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished)
{
if (image){
flag = YES;
downloadProgress++;
}
}];
If the overlay you are trying to show is something like a dimmed background in where the image is set on the middle and judging by the type of loading you are trying to get. I would use an UIView with an image view, a web view and an activity indicator or something to show the loading.
User presses the gif, you show the UIView with the UIImage view with a background color of black (for example) and with a certain alpha (0.7) which will be the dimmed background, you should also show the activity indicator running, and be sure that the web view is hidden.
Once the web view has finished loading and using the "webViewDidFinishLoad:" delegate method, you can get its size and adjust it accordingly inside the view, then set the webview hidden property to NO (and dont forget to hide the activity indicator too).
The "#property(nonatomic) BOOL scalesPageToFit" from the UIWebView controls the user being able to zoom:
If YES, the webpage is scaled to fit and the user can zoom in and zoom
out. If NO, user zooming is disabled. The default value is NO.
Additionally, you might want to show a second UIImage view with the preview of the gif (the one you are using to show the user to select the gif will work) Then just hide the image view and show the webview when the gif is ready to be displayed.
I would suggest using OLImageView.
It has accurate playback.
It also supports incremental loading so you will know the frame as fast as you can.
+ (instancetype)imageWithIncrementalData:(NSData *)data;
Also you can pause the animation just by calling stopAnimating .
For the overlay, you can create a MyGifContainerView that contains both OLImageView and MyOverlayView, should be easy to do.
you can get the Size of a UIWebView by checking it's UIScrollView
webview.scrollView.frame
Kind of hacky but this usually works for me in getting the size of the content inside the webView.
Then check it's has loaded by using the delegate as Sha suggested
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
... Show Web View
}

How to use UIActivityIndicator as a status indicator in real time for iOS?

]]I am trying to build a UIActivityIndicator for my iOS app so that it is displaying the current state of certain processes that are running, and each quarter segment of the wheel will be highlighted by a different colour, depending on the status.
All of the tutorials I have seen show how to build an activity indicator that spins while something is loading, whereas I need the indicator to remain on the screen and show state. I need the indicator to remain hollow, with only the circumference that is coloured. How would I do this?
Core graphics. You'll have to make a custom class that inherits from UIView and do all the drawing yourself. You'll probably override a setter for a float (progress), which will update the display (using [self setNeedsDisplay]. Then in the drawRect: method you'll use this class property of progress to determine what color and what angle to draw/fill in the view. Check out the source of MBProgressHud for some reference: MBProgressHUD

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