zoukankan      html  css  js  c++  java
  • 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];
    }
  • 相关阅读:
    Scala中有关时间的转换操作
    Scala基础
    IDEA 从github拉取代码与推送代码
    IDEA把项目推送到github
    Flink on yarn-session启动出错 Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.yarn.exceptions.YarnException org.apache.hadoop.conf.Configuration
    spark sql导出数据到mysql 出现BLOB类型
    编译Kafka0.11版本遇到的坑!!! 日志无法打印og4j:WARN No appenders could be found for logger(kafka.$Kafka.)
    C#
    js得到分页栏
    js获取浏览器地址栏传递的参数
  • 原文地址:https://www.cnblogs.com/foxmin/p/2393603.html
Copyright © 2011-2022 走看看