• iPhone控件之UIActivityView


    //
    // UITestViewController.m
    // UITest
    //

    #import "UITestViewController.h"

    @implementation UITestViewController


    - (void)viewDidLoad {

    [super viewDidLoad];

    [self.view setBackgroundColor:[UIColor blackColor]];

    UIActivityIndicatorView *myActivityView = [[UIActivityIndicatorView alloc]
    initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

    CGRect activityFrame = CGRectMake(130,100,50,50);
    [myActivityView setFrame:activityFrame];

    [myActivityView startAnimating];

    [self.view addSubview:myActivityView];

    [myActivityView release];
    }

    - (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
    }

    - (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    }


    - (void)dealloc {
    [super dealloc];
    }

    @end

    在UIActivityIndicatorView与UITableView混用时,如果直接在点击表格的时间中来调用UIActivityIndicatorView,可能该视图的出现仍然会延迟,解决方法是重新开启一个线程来执行该方法,实例如下:

    - (void)viewDidLoad
    {
     myview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 768, 1004)];
        [myview setBackgroundColor:[UIColor blackColor]];
        [myview setAlpha:0.5];
        myActivityView = [[UIActivityIndicatorView alloc] 
                          initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
        [myActivityView setFrame:CGRectMake(0, 0, 50, 50)];
        myActivityView.center = self.view.center;
        myActivityView.hidesWhenStopped = YES;
        
        UILabel *mylabel = [[UILabel alloc] initWithFrame:CGRectMake(myActivityView.frame.origin.x-50,myActivityView.frame.origin.y + 50, 200, 50)];
        mylabel.text = @"数据加载中⋯";
        mylabel.backgroundColor = [UIColor clearColor];
        mylabel.font = [UIFont systemFontOfSize:22];
        mylabel.textColor = [UIColor whiteColor];
        [myview addSubview:mylabel];
        [myview addSubview:myActivityView];
    }

    在点击表格中开启线程:

    //处理点击事件
    -(void)tableView:(UITableView*)tableView 
    didSelectRowAtIndexPath:(NSIndexPath*)indexPath
    {    
        
        [NSThread detachNewThreadSelector:@selector(addActivity) toTarget:self withObject:nil]; 
    
    //⋯⋯⋯⋯⋯⋯
    
    }

    实现方法:

    - (void)addActivity{
        [self.view addSubview:myview];
        [myActivityView startAnimating];
    }
  • 相关阅读:
    火币Huobi API Websocket
    火币Huobi API
    OKEX API(Websocket)
    OKEX API
    Linux下Miniconda量化环境安装
    Numba:高性能Python编译器
    十进制和十六进制互相转换
    JavaScript 原型和原型链
    Redux 进阶之 react-redux 和 redux-thunk 的应用
    Vue 中 $nextTick() 的应用
  • 原文地址:https://www.cnblogs.com/foxmin/p/2393603.html
Copyright © 2020-2023  润新知