Hi I'm trying to upload image's from iphone to server in that i given activity indicator for the user to known that image is uploading while clicking upload it will show activity indicator for few minutes.
But my problem is the activity indicator only showing in few images its not showup on all the images pls tell me how to resolve this.
my activity coding .
-(void)temp{
spinner = [[UIActivityIndicatorView alloc initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
//spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:]
spinner.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
[spinner setCenter:CGPointMake(160, 240)]; // (mid of screen) I do this because I'm in landscape mode
[self.view addSubview:spinner];
spinner.color = [UIColor blackColor];
spinner.backgroundColor = [UIColor colorWithWhite:0.2 alpha:0.4];
[spinner startAnimating];
[spinner release];
}
-(void) myMethod{
[spinner stopAnimating];
spinner.hidden = YES;
spinner.color = [UIColor yellowColor];
}
- (IBAction)pushUpload:(id)sender {
[self temp];
[self performSelector:#selector(myMethod) withObject:nil afterDelay:5.0f];
}
Instead of ActivityIndicator use AsynchronousImageView It will automatically add activityindicator while loading an image.
[AsynObj loadImageFromURL:[NSURL URLWithString:ImageUrl]];
You can get the AsyncImageView classes from the following link https://github.com/nicklockwood/AsyncImageView
I hope it will help!
Related
I am showing spinner(UIActivityIndicator) while download is going on. It shows spinner as download starts, but it doesn't stop showing once download is finished. i have seen some question for the same issue but did not help. I need to make it work in ios7 as well as iOS8.
I am using below code...
- (void) startSpinner:(NSString *)message {
container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
container.center = self.view.center;
container.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:0.4];
container.layer.cornerRadius = 10;
container.layer.masksToBounds = true;
container.tag = 134;
activityLabel = [[UILabel alloc] init];
activityLabel.frame = CGRectMake(0, 70, 100, 30);
activityLabel.text = message;
activityLabel.textColor = [UIColor darkGrayColor];
activityLabel.textAlignment = NSTextAlignmentCenter;
activityLabel.font = [UIFont boldSystemFontOfSize:10];
[container addSubview:activityLabel];
activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.center = CGPointMake(container.frame.size.width/2, container.frame.size.height/2);
[container addSubview:activityIndicator];
[self.view addSubview:container];
[activityIndicator startAnimating];
}
-(void)stopSpinner{
[activityIndicator stopAnimating];
container = [self.view viewWithTag:134];
[container removeFromSuperview];
activityIndicator = nil;
NSLog(#"activity indicator should be removed %#",activityIndicator);
}
And one more issue it does not show spinner in the center of the device screen.
Any help will be appreciated....
There are a few things wrong here.
container.center = self.view.center;
If you are trying to center the container in self.view, then this won't do it. self.view.center is the center of the view's frame but you would need to use the center of the view's bounds. Here is the corrected code:
container.center = CGPointMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds));
You also need to change how you set the activity indicator's frame:
activityIndicator.center = CGPointMake(CGRectGetMidX(container.bounds), CGRectGetMidY(container.bounds));
Also, if you call startSpinner more than once, you can have more than one spinner added to the view, which could possibly be the reason your spinner doesn't seem to be stopping. I recommend that you alloc and init only one spinner and do it in the class constructor. You can do the same with the container and activityLabel objects. Alternatively, you could call stopSpinner at the top of startSpinner (and add some null-checks in stopSpinner to avoid referencing a null pointer).
It's impossible to say for sure based on your code why it appears that the spinner doesn't stop, but my guess is that you're calling startSpinner several times in a row without any intervening call to stopSpinner.
If you're only calling stopSpinner once then verify that you're doing so in the main thread.
You can add the spinner view on navigation controller, so it will look at the center as you want. I think this will solve your problem.
[self.navigationController.view addSubview:coverView];
And don't forget to remove it from self.navigationController.view
How can I set color of bottom view with all elements of UIActivityViewController?
My current implementation changes color for all view -
CopyLink *copyLink = [[CopyLink alloc]init];
copyLink.delegate = self;
self = [self initWithActivityItems:#[emailActivity] applicationActivities:#[copyLink]];
self.view.backgroundColor = [UIColor redColor];
self.completionHandler = ^(NSString *activityType, BOOL completed)
You can't do this, the UIActivityViewController is supposed to take form of an overlay sheet, I doubt you can even access the view of it let alone its background colour, You may have to create a custom Subview and then use that as the subview
Here is the best way to use UIActivityViewController :
-(void)doStartStopSpinner
{
if (![spinner isAnimating])
{
spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
spinner.center = self.view.center;
spinner.backgroundColor = [UIColor colorWithRed:0.0/255.0 green:0.0/255.0 blue:0.0/255.0 alpha:0.6];
[self.view addSubview:spinner];
[spinner startAnimating];
}
else
{
[spinner stopAnimating];
[spinner removeFromSuperview];
[viewUpgradePro removeFromSuperview];
}
}
Hope it'll help.
I have added splash screen by doing project->General tab-> Launch Images->
From here i have taken two images according to the size and its working very fine too.
Now i want to put an Activity Indicator onto it.
So before loading of my DB and files, the splash as well as the indicator should be displayed.
What can i do for this?
I also tried after some suggestions
i did like this
[self performSelector:#selector(loadingViewFade) withObject:nil];
(void) loadingViewFade
loadingView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)];
loadingView.image = [UIImage imageNamed:#"splashscreen_640x960"];
[_window addSubview:loadingView];
[_window bringSubviewToFront:loadingView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:3.0];
[UIView setAnimationDelay:3.0];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:_window cache:YES];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(startupAnimationDone:finished:context:)];
loadingView.alpha = 0.5f;
[UIView commitAnimations];
//Create and add the Activity Indicator to loadingView
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
activityIndicator.alpha = 1.0;
activityIndicator.center = CGPointMake(160, 430);
activityIndicator.hidesWhenStopped = NO;
UILabel *text = [[UILabel alloc]initWithFrame:CGRectMake(140, 435, 160, 30)];
text.backgroundColor = [UIColor clearColor];
text.textColor = [UIColor whiteColor];
text.font = [UIFont systemFontOfSize:14];
text.text = #"Loading...";
[loadingView addSubview:text];
[loadingView addSubview:activityIndicator];
[loadingView addSubview:activityIndicator];
[activityIndicator startAnimating];
(void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
[loadingView removeFromSuperview];
Again the splash as well as the indicator isnt displaying rather the default screen is being loaded untill the database loads.. Please help me out
I think you should create your own splash screen, and add a UIActivityIndicator to this splash screen by programmatically.
project->General tab-> Launch Images-> will add the default splash or loading screen to your project. You can not show activity indicator on the default image. To show loading message to Activity indicator you need to add your splash view controller which has the background image as default image which you set before. Also one Activity indicator to show the loading status. Once you are done with loading of database and other thing stop animating activity indicator and dismiss the splash screen.
i am trying to show UIActivityIndicator on viewDidLoad of a screen. its working in another project but not sure why it's not displayed here.
I am calling the showSplashScreen fromviewDidLoad of other screen.
+(void) showSplashScreen
{
UIView *mainScreen = [[[UIApplication sharedApplication]delegate]window];
UIView *windowBlocker = [[UIView alloc]initWithFrame:mainScreen.frame];
windowBlocker.tag = 999;
windowBlocker.backgroundColor = [UIColor clearColor];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((mainScreen.frame.size.width), (mainScreen.frame.size.height), 50, 50)];
imageView.layer.backgroundColor=[[UIColor colorWithRed:200 green:0 blue:0 alpha:0.5] CGColor];
imageView.layer.cornerRadius=10;
imageView.layer.masksToBounds = YES;
[windowBlocker addSubview:imageView];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[windowBlocker addSubview:spinner];
spinner.center = mainScreen.center;
[spinner startAnimating];
}
nothing happens. Any idea? I am trying for iPad.
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[imageView addSubview:spinner];
spinner.center = mainScreen.center;
[windowBlocker addSubview:imageView];
[self.view addSubview: mainScreen];
[spinner startAnimating];
//Yoy forget to add windowBlocker in mainview
[Self.view addSubview:windowBlocker];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.center = mainScreen.center;
[spinner startAnimating];
[windowBlocker addSubview:spinner];
//Try this code
looks like the issue is that you haven't added windowBlocker to the screen.
try:
[mainScreen addSubview:windowBlocker];
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self performSelector:#selector(addSplash) withObject:nil afterDelay:0.5];
}
-(void)addSplash {
[[self class] showSplashScreen];
}
+(void) showSplashScreen
{
UIView *mainScreen = [[[UIApplication sharedApplication]delegate]window];
UIView *windowBlocker = [[UIView alloc]initWithFrame:mainScreen.frame];
windowBlocker.tag = 999;
windowBlocker.backgroundColor = [UIColor redColor];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((mainScreen.frame.size.width), (mainScreen.frame.size.height), 50, 50)];
imageView.layer.backgroundColor=[[UIColor colorWithRed:200 green:0 blue:0 alpha:0.5] CGColor];
imageView.layer.cornerRadius=10;
imageView.layer.masksToBounds = YES;
[windowBlocker addSubview:imageView];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[windowBlocker addSubview:spinner];
spinner.center = mainScreen.center;
[spinner startAnimating];
[[[[UIApplication sharedApplication]delegate]window] addSubview:windowBlocker];
}
As I added some delay with 0.5 because when i called function in ViewDidLoad orViewWillAppear some reason view not initaliaze yet so i provide some delay or you can use the viewDidAppear for as an option of this situation like and only this function and remove viewWillAppear and addSplash and add only this
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[[self class] showSplashScreen];
}
Change this ... it works for you
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
spinner.color=[UIColor greenColor];
spinner.center = self.view.center;
[spinner startAnimating];
[windowBlocker addSubview:spinner];
In my UIViewController's loadView method I start a UIActivityIndicator. Later in loadView I load a complex UIView, which takes about 2-3 secs to load. (UIScrollView with a lot of pictures more specifically). My problem is that the UIActivityIndicator spinner is only visible, after my other layer has loaded too. (which is of course useless to me). What is a correct way to handle this?
- (void)loadView {
CGRect fullScreenRect=[[UIScreen mainScreen] bounds];
UIView *contentView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 340, fullScreenRect.size.width)]autorelease];
self.view = contentView;
spinner = [[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] autorelease];
spinner.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
spinner.center = self.view.center;
[self.view addSubview:spinner];
[spinner startAnimating];
scrollView=[[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 340, fullScreenRect.size.width)]autorelease];
...setting up scrollView...
[self.view addSubview:scrollView];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[spinner removeFromSuperview];
}
I have found a somewhat similar thread:
UIActivityIndicatorView not showing until after loading done
But it suggests to load things in a background thread, but loading and displaying a UIView is only possible in the main thread as far as I know.
I am a beginner, and sorry if my question is fundamentally wrong.
I managed to make it the way Carl Veazey suggested. It was pretty easy actually. I spawned a new background thread, and loaded my UIScrollView there.
I used, in LoadView:
spinner = [[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] autorelease];
spinner.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
spinner.center = self.view.center;
[self.view addSubview:spinner];
[spinner startAnimating];
[self performSelectorInBackground:#selector(populateScrollView) withObject:nil];
And:
-(void) populateScrollView{
...creating scrollView...
[self.view addSubview:scrollView];
[spinner removeFromSuperview];
}
It works perfectly. What is really weird for me, is that I am adding the scrollview to the UI in a background thread, not in the main thread. I thought I could only mess with the UI in the main thread.
(I could do the same thing with GCD. When the background thread finished loading the scrollview, I could display scrollview in the main thread's queue. But the former solution somehow works as well...)
Sorry for ugly text formatting.
There is a very cute way to do what you want.
Firstly you have to show the indicator view and only after a little amount of time (0.1 sec or even lesser) you ask your scrollView to populate.
- (void)loadView {
CGRect fullScreenRect=[[UIScreen mainScreen] bounds];
UIView *contentView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 340, fullScreenRect.size.width)]autorelease];
self.view = contentView;
spinner = [[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] autorelease];
spinner.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
spinner.center = self.view.center;
[self.view addSubview:spinner];
[spinner startAnimating];
double delayInSeconds = 0.1;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
scrollView=[[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 340, fullScreenRect.size.width)]autorelease];
...setting up scrollView...
[self.view addSubview:scrollView];
});
}
Try this simple method, Its working well for me....
UIActivityIndicatorView *activityIndicator= [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(0, 0, 50, 50)];
activityIndicator.layer.cornerRadius = 05;
activityIndicator.opaque = NO;
activityIndicator.backgroundColor = [UIColor colorWithWhite:0.0f alpha:0.6f];
activityIndicator.center = self.view.center;
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
[activityIndicator setColor:[UIColor colorWithRed:0.6 green:0.8 blue:1.0 alpha:1.0]];
[self.view addSubview: activityIndicator];
Add following lines while load your view
//-- Add this line while processing to load your view
[activityIndicator startAnimating];
//-- Add this line when after you view loaded
[activityIndicator stopAnimating];