//
// ActivityView.h
//
// Copyright 2010. All rights reserved.
//
#import <UIKit/UIKit.h>
#define kAnimationDurationStart 2
#define kAnimationDurationEnd 1
@interface ActivityView : NSObject {
IBOutlet UILabel *messageLabel;
IBOutlet UIView *view;
BOOL isShow;
}
@property (nonatomic, readonly) UILabel *messageLabel;
@property (nonatomic, readonly) UIView *view;
@property (nonatomic) BOOL isShow;
+ (ActivityView *)sharedActivityView;
- (void)showWithMessage:(NSString *)message animate:(BOOL)animate;
- (void)hide:(BOOL)animate;
@end
//
// ActivityView.m
//
// Copyright 2010 All rights reserved.
//
#import "ActivityView.h"
@implementation ActivityView
@synthesize messageLabel,view, isShow;
//单例模式
static ActivityView *activityView;
- (id) init {
self = [super init];
if (self != nil) {
[[NSBundle mainBundle] loadNibNamed:@"ActivityView" owner:self options:nil];
[[[UIApplication sharedApplication] keyWindow] addSubview:view];
[view setFrame:CGRectMake(0, [UIApplication sharedApplication].statusBarFrame.size.height-view.frame.size.height, view.frame.size.width, view.frame.size.height)];
isShow = NO;
}
return self;
}
+ (ActivityView *)sharedActivityView {
if (!activityView) {
activityView = [[ActivityView alloc]init];
}
return activityView;
}
- (void)showWithMessage:(NSString *)message animate:(BOOL)animate {
isShow = YES;
messageLabel.text = message;
[view.superview bringSubviewToFront:view];
if ( animate )
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:kAnimationDurationStart];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[view setFrame:CGRectMake(0, [UIApplication sharedApplication].statusBarFrame.size.height, view.frame.size.width, view.frame.size.height)];
[UIView commitAnimations];
}
else
{
[view setFrame:CGRectMake(0, [UIApplication sharedApplication].statusBarFrame.size.height, view.frame.size.width, view.frame.size.height)];
}
}
- (void)hide:(BOOL)animate{
messageLabel.text = @"";
if (animate)
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:kAnimationDurationEnd];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[view setFrame:CGRectMake(0, [UIApplication sharedApplication].statusBarFrame.size.height-view.frame.size.height, view.frame.size.width, view.frame.size.height)];
[UIView commitAnimations];
}
else
{
[view setFrame:CGRectMake(0, [UIApplication sharedApplication].statusBarFrame.size.height-view.frame.size.height, view.frame.size.width, view.frame.size.height)];
}
[[UIApplication sharedApplication] keyWindow].userInteractionEnabled = YES;
isShow = NO;
}
@end
调用方法
[[ActivityView sharedActivityView] showWithMessage:@"正在下载数据" animate: NO];
[[ActivityView sharedActivityView] hide: YES];
如何更改ActivityView位置,
修改 setFrame方法
coco china里有人提供了另外一个方法:
#define activityViewTag 0x98751234
@interface UIView (UIViewUtils)
- (void)showActivityViewAtCenter;
- (void)hideActivityViewAtCenter;
- (UIActivityIndicatorView*)createActivityViewAtCenter:(UIActivityIndicatorViewStyle)style;
- (UIActivityIndicatorView*)getActivityViewAtCenter;
@end
#import "UIViewUtils.h"
@implementation UIView (UIViewUtils)
- (UIActivityIndicatorView*)createActivityViewAtCenter:(UIActivityIndicatorViewStyle)style
{
static int size = 30;
UIActivityIndicatorView* activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:style];
activityView.frame = CGRectMake([UIScreen mainScreen].bounds.size.width/2 - size/2, [UIScreen mainScreen].bounds.size.height/2 - size*2, size, size);
activityView.tag = activityViewTag;
[self addSubview:activityView];
[activityView release];
return activityView;
}
- (UIActivityIndicatorView*)getActivityViewAtCenter
{
UIView* view = [self viewWithTag:activityViewTag];
if (view != nil && [view isKindOfClass:[UIActivityIndicatorView class]]){
return (UIActivityIndicatorView*)view;
}
else {
return nil;
}
}
- (void)showActivityViewAtCenter
{
UIActivityIndicatorView* activityView = [self getActivityViewAtCenter];
if (activityView == nil){
activityView = [self createActivityViewAtCenter:UIActivityIndicatorViewStyleWhite];
}
[activityView startAnimating];
}
- (void)hideActivityViewAtCenter
{
UIActivityIndicatorView* activityView = [self getActivityViewAtCenter];
if (activityView != nil){
[activityView stopAnimating];
}
}
@end
分享到:
相关推荐
因此,"iPhone UITableView异步加载图片"是解决这个问题的关键技术。 异步加载图片的基本思想是在主线程之外的其他线程(通常为后台线程)下载和处理图片,避免阻塞用户界面。在UITableView中,我们通常会在cell...
这篇文章“js仿iPhone手机端alert,loading,正在加载...”提供了一种实现这一功能的方法。我们将深入探讨这些元素的实现方式,并通过JavaScript来创建类似iOS体验的交互。 首先,我们来看`alert`。在原生的...
因此,"IPhone TableView 图片异步加载"这一主题显得尤为重要。 异步加载是指在主线程之外的子线程中执行任务,不会阻塞用户界面。对于 `UITableView` 中的图片加载,我们通常采用异步加载策略,以便在后台下载图片...
在Android开发中,为了提供与iOS设备相似的用户体验,开发者有时会选择模仿iPhone的特定界面元素,如网络加载进度条。本项目"模仿Iphone网络加载进度条 demo"提供了一个实现这一功能的源码示例。这个demo可以帮助...
在iOS应用开发中,特别是在iPhone平台上,为了提供流畅的用户体验,高效地加载和显示网络图片是一项重要的技术。EGOTableViewPullRefresh 是一个优秀的开源库,它专门针对UITableView进行了优化,实现了下拉刷新功能...
6. **显示加载指示器**:在加载过程中,可以显示一个加载动画或者提示文字,告诉用户数据正在加载。 在实际应用中,还可以考虑优化用户体验,比如添加加载状态的处理(加载中、加载失败、无更多数据等),以及错误...
在这个例子中,我们将探讨如何在iPhone应用中通过代码自行加载`nib`文件来显示一个`UITableView`。 首先,我们需要了解`UITableView`是iOS中的一个核心组件,用于展示列表或表格形式的数据。通常,`UITableView`会...
"iphone uitableview图片延迟加载实例"就是一种实现这种技术的方式,通过这个例子,开发者可以学习如何在UITableView中高效地显示图片。 在这个实例中,我们主要关注以下几个关键知识点: 1. **...
2. **呈现方式**:Popover在iPhone上可能以全屏模态视图、半透明遮罩层或者简单的下拉菜单等形式出现,以适应小屏幕环境。 3. **交互设计**:在iPhone上,考虑用户体验是至关重要的。Popover需要有清晰的入口和退出...
AVPlayer负责加载和播放媒体资源,而AVPlayerLayer则是一个CALayer子类,用于在屏幕上显示视频内容。 2. **URLSession**:为了加载远程或本地的视频文件,开发者通常会使用URLSession。它允许应用程序异步地下载或...
对于移动设备,还需要考虑响应式设计,确保页面在不同尺寸的屏幕上都能正确显示。 二、响应式设计 响应式设计是确保网页在不同设备上呈现良好效果的关键。iPhone 13具有较高的分辨率和不同的屏幕比例,因此需要使用...
标题"iPhone-PDF以图片形式显示"涉及到的是如何在iPhone上查看以图片形式呈现的PDF文件。 在iOS系统中,内置的“文件”应用支持打开和预览PDF文件,但默认情况下它并不会将PDF转化为图片。如果你收到的PDF是以图片...
当用户松开手指时,通常会有一个动画效果,显示一个刷新指示器,表示后台正在加载新的数据。同样,上拉加载更多是在列表底部向上滑动,用于加载更多的内容。 1. **使用第三方库**: 在Android中,有许多第三方库...
它包含了所有必要的资源和代码,用于将iPhone 6的主屏幕转换成类似Apple Watch的界面,提供时间显示、通知中心、快捷操作等功能。 4. `preferenceloader_2.2.2_iphoneos-arm.deb`:PreferenceLoader是一个允许Cydia...
首先,UIActivityIndicatorView是iOS自带的一种基础加载指示器,它通常表现为一个旋转的小圆圈,表示应用正在进行后台处理。然而,它的功能相对简单,只提供了一个活动指示器,无法显示额外的信息或自定义样式。而...
而"android ExpandableListView子集异步加载+IphoneTreeView"这个主题主要关注如何在`ExpandableListView`中实现子集的异步加载以及模仿iPhone风格的树形视图(`IphoneTreeView`)。 首先,让我们深入理解`...
本教程将指导开发者如何在不同iPhone型号上集成MJRefresh,并特别关注如何进行iPhoneX的适配工作,确保刷新控件在屏幕顶部的安全区域内正常显示和操作。 【知识点详述】 1. **MJRefresh简介**:MJRefresh是由...
例如,"Texture-Square"可能是一个包含多个正方形纹理的文件,用于一次性加载并显示多个类似的图形元素。 此外,OpenGL ES还支持MIPmapping,这是一种预计算的技术,用于提高远距离和小尺寸纹理的渲染质量。MIPmaps...
加载框是用户界面中的一个重要元素,通常用于指示应用正在进行后台处理或数据加载,提高用户体验。在这个项目中,开发者可能对加载框进行了自定义设计,并考虑了不同屏幕尺寸的适配问题,确保在各种设备上都能正确...
网站模板的优点在于节省时间和成本,它们通常包含响应式设计,能适应不同设备的屏幕大小,确保在iPhone、iPad甚至是桌面电脑上都能良好显示。 【压缩包子文件的文件名称列表】中的"iphone_store"可能是指这个模板的...