- //开启状态栏动画
- [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
- //关闭状态栏动画
- [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
- //隐藏状态栏
- [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:YES];
- //显示状态栏
- [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:YES];
- //隐藏状态栏
- [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:YES];
- //重新设定窗口的显示区域
- [[UIApplication sharedApplication].keyWindow setFrame:CGRectMake(0, 0, 320, 480)];
- //重新设定标题栏显示的位置
- [self.navigationController.navigationBar setFrame:CGRectMake(0, 0, 320, 44)];
- #import <Three20/Three20.h>
- @interface ViewController : TTViewController
- {
- //下载进度显示视图
- UITextView*textView;
- //状态条顶部Loading动画视图
- UIActivityIndicatorView *activity;
- //计时器
- NSTimer *timer;
- //应用程序的句柄
- UIApplication *app;
- //计数
- int timeCount;
- }
- @end
- #import "ViewController.h"
- @implementation ViewController
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- //设置标题栏文字
- self.title =@"雨松MOMO软件开发";
- //设置视图背景显示颜色
- [self.view setBackgroundColor:[UIColor blackColor]];
- //创建图片视图
- TTImageView *imageview = [[[TTImageView alloc] initWithFrame:
- CGRectMake(100, 50, 120, 120)] autorelease];
- //设置图片视图显示的图片资源
- imageview.defaultImage = TTIMAGE(@"bundle://0.jpg");
- //将图片视图加入整个视图当中
- [self.view addSubview:imageview];
- //按钮的文字信息
- NSArray *titles = [[NSArray alloc] initWithObjects:
- @"隐藏状态栏",
- @"显示状态栏",
- @"更新状态栏",
- nil];
- for (int i =0; i < [titles count]; i++)
- {
- //创建普通按钮
- UIButton *button = [UIButton buttonWithType:1];
- //设置按钮位置
- button.frame = CGRectMake(0, 200 + i * 40, 320, 30);
- //设置按钮现实文字
- [button setTitle:[titles objectAtIndex:i] forState:UIControlStateNormal];
- //设置按钮标记
- button.tag = i;
- //设置按钮点击后 绑定响应方法
- [button addTarget:self action:@selector(ButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
- //将按钮添加入视图中
- [self.view addSubview: button];
- }
- //得到应用程序的句柄
- app = [UIApplication sharedApplication];
- }
- -(void)ButtonPressed:(id)buttonID
- {
- //获取点击的按钮
- UIButton *button = (UIButton *)buttonID;
- switch (button.tag)
- {
- case 0:
- //注解1
- [app setStatusBarHidden:YES withAnimation:YES];
- [app.keyWindow setWindowLevel:UIWindowLevelStatusBar];
- [app.keyWindow setFrame:CGRectMake(0, 0, 320, 480)];
- break;
- case 1:
- //注解2
- [app setStatusBarHidden:NO withAnimation:YES];
- [app.keyWindow setWindowLevel:UIWindowLevelStatusBar];
- [app.keyWindow setFrame:CGRectMake(0, 20, 320, 460)];
- break;
- case 2:
- //注解3
- [app setStatusBarHidden:NO withAnimation:YES];
- [app.keyWindow setWindowLevel:UIWindowLevelStatusBar];
- [app.keyWindow setFrame:CGRectMake(0, 20, 320, 460)];
- [self performSelector:@selector(startUpdate) withObject:nil afterDelay:0.4];
- break;
- }
- //注解4
- [self.navigationController.navigationBar setFrame:CGRectMake(0, 0, 320, 44)];
- }
- - (void)dealloc
- {
- //释放
- TT_RELEASE_SAFELY(textView);
- TT_RELEASE_SAFELY(activity);
- TT_RELEASE_SAFELY(timer);
- TT_RELEASE_SAFELY(app);
- [super dealloc];
- }
- - (void) startUpdate
- {
- if(timer == nil)
- {
- //顶部文本视图
- textView = [[UITextView alloc] initWithFrame:CGRectMake(0, -25, 320, 25)];
- [textView setBackgroundColor:[UIColor blackColor]];
- [textView setText:@"开始更新"];
- [textView setTextColor:[UIColor whiteColor]];
- [textView setTextAlignment:UITextAlignmentCenter];
- [textView setFont:[UIFont systemFontOfSize:15]];
- [app.keyWindow addSubview:textView];
- //注解5
- [UIView beginAnimations:@"anim1" context:nil];
- [UIView setAnimationDuration:1.0];
- textView.alpha = 0.0f;
- textView.alpha = 1.0f;
- [UIView commitAnimations];
- [textView release];
- //注解6
- timer = [NSTimer scheduledTimerWithTimeInterval: 0.1
- target: self
- selector: @selector(handleTimer:)
- userInfo: nil
- repeats: YES];
- //开始播放loading动画
- [self addLoading];
- }
- }
- - (void) handleTimer: (NSTimer *) t
- {
- //开始计数,没进该方法一次++
- timeCount++;
- //计数器小于100表示未下载完毕
- if(timeCount <=100)
- {
- //绘制显示百分比
- NSString *text = [NSString stringWithFormat:@"读取进度百分之:%d ",timeCount];
- [textView setText:text];
- }else
- {
- //计数器大于100表示下载完毕
- [textView setText:@"读取完毕"];
- timeCount = 0;
- //删除时间计时器
- [self removeTimer];
- //删除读取动画
- [self removeLoading];
- //注解7
- [UIView beginAnimations:@"anim" context:nil];
- [UIView setAnimationDuration:1.0];
- textView.alpha= 1.0f;
- textView.alpha = 0.0f;
- [UIView commitAnimations];
- }
- }
- - (void)addLoading
- {
- //创建Loading动画视图
- activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
- //设置动画视图的风格,这里设定它位白色
- activity.activityIndicatorViewStyle=UIActivityIndicatorViewStyleWhite;
- //设置它显示的区域
- activity.frame = CGRectMake(0, -18, 20, 18);
- //将视图加入窗口中
- [app.keyWindow addSubview:activity];
- //开始播放动画
- [activity startAnimating];
- //释放
- [activity release];
- }
- -(void)removeLoading
- {
- //结束动画
- [activity stopAnimating];
- //删除动画视图
- [activity removeFromSuperview];
- }
- -(void)removeTimer
- {
- //停止时间计时器
- TT_INVALIDATE_TIMER(timer);
- //等价于上面的方法
- // //停止时间计时器
- // [timer invalidate];
- // //让它等于nil
- // timer = nil;
- }
- @end
- #define TT_RELEASE_SAFELY(__POINTER) { [__POINTER release]; __POINTER = nil; }
- #define TT_INVALIDATE_TIMER(__TIMER) { [__TIMER invalidate]; __TIMER = nil; }
- // Release a CoreFoundation object safely.
- #define TT_RELEASE_CF_SAFELY(__REF) { if (nil != (__REF)) { CFRelease(__REF); __REF = nil; } }
下载地址:
http://down.51cto.com/data/369016
(下载后必需搭建three20环境成功后才能运行~ 因为three20为引用加载,所以程序路径都是我本机的请见谅!或者你可可以将你的Three20路径修改的和我一样就可以直接运行啦,我的路径是:User (用户) -> Share(共享)->Three20)。