dd

IOS学习笔记(八)之UIActivityIndicatorView(活动指示器视图)的基本概念和使用方法

jerry IOS 2015年11月27日 收藏

UIActivityIndicatorView:

作用:进行提示用户当前正在加载进度,该控件可以消除用户等待的心理事件,增加用户体验。

首先来看下官方解说:


Use an activity indicator to show that a task is in progress. An activity indicator appears as a “gear” that is either spinning or stopped.

You control when an activity indicator animates by calling the startAnimating and stopAnimating methods. To automatically hide the activity indicator when animation stops, set the hidesWhenStopped property to YES.

常用的属性和方法:


- (void)startAnimating; //开始进度动画

- (void)stopAnimating; //停止进度动画

- (BOOL)isAnimating;  //检测是否动画在执行

实例代码:


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor redColor];
    
    UIActivityIndicatorView *activityView=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    activityView.center=CGPointMake(160, 155);
    [activityView startAnimating];
    [self.window addSubview:activityView];
    [activityView release];
    
    //定时3s之后,自动停止运行
    [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(test:) userInfo:activityView repeats:NO];
    
    [self.window makeKeyAndVisible];
    return YES;
}

-(void)test:(NSTimer *)timer{
    UIActivityIndicatorView *view=timer.userInfo;
    [view stopAnimating];
    NSLog(@"进度结束...");
}





dd