菊花怪
来源:互联网 发布:r语言数据挖掘 编辑:程序博客网 时间:2024/04/28 14:12
//// MyProgressView.h// test2//// Created by MSMW on 15/3/18.// Copyright (c) 2015年 msmw. All rights reserved.//#import <Foundation/Foundation.h>#import <UIKit/UIKit.h>@interface MyProgressView : UIView{ UIActivityIndicatorView* indicator; UILabel* label; BOOL visible,blocked; UIView* maskView; CGRect rectHud,rectSuper,rectOrigin;//外壳区域、父视图区域 UIView* viewHud;//外壳 }@property (assign) BOOL visible;-(id)initWithFrame:(CGRect)frame superView:(UIView*)superView;-(void)show:(BOOL)block;// block:是否阻塞父视图-(void)hide;-(void)setMessage:(NSString*)newMsg;-(void)alignToCenter;@end
//// MyProgressView.m// test2//// Created by MSMW on 15/3/18.// Copyright (c) 2015年 msmw. All rights reserved.//#import "MyProgressView.h"@implementation MyProgressView@synthesize visible;-(id)initWithFrame:(CGRect)frame superView:(UIView*)superView{ rectOrigin=frame; rectSuper=[superView bounds]; //保持正方形比例 rectHud=CGRectMake(frame.origin.x,frame.origin.y, frame.size.width, frame.size.width); self = [super initWithFrame:rectHud]; if (self) { self.backgroundColor =[UIColor clearColor]; self.opaque = NO; viewHud=[[UIView alloc]initWithFrame:rectHud]; [self addSubview:viewHud]; indicator=[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle: UIActivityIndicatorViewStyleWhiteLarge]; double gridUnit=round(rectHud.size.width/12); float ind_width=6*gridUnit; indicator.frame=CGRectMake( 3*gridUnit, 2*gridUnit, ind_width, ind_width); [viewHud addSubview:indicator]; CGRect rectLabel=CGRectMake(1*gridUnit, 9*gridUnit, 10*gridUnit, 2*gridUnit); label=[[UILabel alloc]initWithFrame:rectLabel]; label.backgroundColor=[UIColor clearColor]; label.font=[UIFont fontWithName:@"Arial" size:14]; label.textAlignment=NSTextAlignmentCenter; label.textColor=[UIColor whiteColor]; label.text=@"请等待..."; label.adjustsFontSizeToFitWidth=YES; [viewHud addSubview:label]; visible=NO; [self setHidden:YES]; [superView addSubview:self]; } return self; }#pragma mark Drawing- (void)drawRect:(CGRect)rect { if(visible){ CGContextRef context = UIGraphicsGetCurrentContext(); CGRect boxRect = rectHud; // 绘制圆角矩形 float radius = 10.0f; // 路径开始 CGContextBeginPath(context); // 填充色:灰度0.0,透明度:0.1 CGContextSetGrayFillColor(context,0.0f, 0.25); // 画笔移动到左上角的圆弧处 CGContextMoveToPoint(context,CGRectGetMinX(boxRect) + radius, CGRectGetMinY(boxRect)); // 开始绘制右上角圆弧:圆心x坐标,圆心y坐标,起始角,终止角,方向为顺时针 CGContextAddArc(context,CGRectGetMaxX(boxRect) - radius, CGRectGetMinY(boxRect) + radius, radius,3*(float)M_PI/2 , 0, 0); // 开始绘制右下角圆弧 CGContextAddArc(context,CGRectGetMaxX(boxRect) - radius, CGRectGetMaxY(boxRect) - radius, radius, 0 , (float)M_PI / 2, 0); // 开始绘制左下角圆弧 CGContextAddArc(context,CGRectGetMinX(boxRect) + radius, CGRectGetMaxY(boxRect) - radius, radius, (float)M_PI / 2, (float)M_PI, 0); // 开始绘制左上角圆弧 CGContextAddArc(context,CGRectGetMinX(boxRect) + radius, CGRectGetMinY(boxRect) + radius, radius, (float)M_PI, (float)M_PI / 2, 0); NSLog (@"M_PI:%f",(float)M_PI);// NSLog(@"MinX is:%f",CGRectGetMinX(boxRect));// NSLog(@"MaxX is:%f",CGRectGetMaxX(boxRect));// NSLog(@"MinY is:%f",CGRectGetMinY(boxRect));// NSLog(@"MaxY is:%f",CGRectGetMaxY(boxRect)); // CGContextClosePath(context);// 关闭路径 CGContextFillPath(context);// 填充路径,该函数自动关闭路径 //将画面按照这个方向平移 //[self setFrame:CGRectOffset(self.frame, 100, 160)]; //这行代码是最新添加的,表示绘制结束后,讲画面放到屏幕最中间 [self alignToCenter]; } }#pragma mark Action-(void)show:(BOOL)block{ if (block && blocked==NO) { CGPoint offset=self.frame.origin; // 改变视图大小为父视图大小 self.frame=rectSuper; viewHud.frame=CGRectOffset(viewHud.frame, offset.x, offset.y); if (maskView==nil) { maskView=[[UIView alloc]initWithFrame:rectSuper]; }else{ maskView.frame=rectSuper; } maskView.backgroundColor=[UIColor clearColor]; [self addSubview:maskView]; [self bringSubviewToFront:maskView]; blocked=YES; } [indicator startAnimating]; [self setHidden:NO]; [self setNeedsLayout]; visible=YES; }#pragma mark 将这个东东隐藏-(void)hide{ visible=NO; [indicator stopAnimating]; [self setHidden:YES]; }#pragma mark 改变里面的文字-(void)setMessage:(NSString*)newMsg{ label.text=newMsg; }#pragma mark 将这个东东居中-(void)alignToCenter{ CGPoint centerSuper={rectSuper.size.width/2,rectSuper.size.height/2}; CGPoint centerSelf={self.frame.origin.x+self.frame.size.width/2, self.frame.origin.y+self.frame.size.height/2}; CGPoint offset={centerSuper.x-centerSelf.x,centerSuper.y-centerSelf.y}; CGRect newRect=CGRectOffset(self.frame, offset.x, offset.y); [self setFrame:newRect]; rectHud=newRect; // NSLog(@"newRect:%f,%f",newRect.origin.x,newRect.origin.y); }/*// Only override drawRect: if you perform custom drawing.// An empty implementation adversely affects performance during animation.- (void)drawRect:(CGRect)rect { // Drawing code}*/@end
本来在别的地方看见的。但是代码有点问题 经过修改可以用了 。这个菊花怪比较简单 用的时候只需要
// 无敌风火轮 indicator = [[MyProgressView alloc]initWithFrame:CGRectMake(0, 0, 120, 120) superView:self.view]; [indicator setMessage:@"正在努力加载,请稍候..."]; if (indicator.visible==NO) { [indicator show:NO]; }else { [indicator hide]; }就可以了。什么时候想让菊花怪停下来就在那个地方让indicator hide就好了
0 0
- 菊花怪
- 菊花
- 菊花
- 和法规和规范菊花怪
- 菊花台
- 菊花台
- 《 菊花台》
- 菊花台
- 菊花台
- 题菊花
- 菊花链
- 菊花女
- 菊花2
- 菊花控件:
- 菊花加载
- 菊花加载
- 菊花生成器
- 菊花加载
- 你不知道的 collider
- CLPlacemark 英文环境下获取中文信息
- HTTP 状态管理机制——RFC6265翻译文档
- css中的label标签
- 输入框-邮箱自动补充
- 菊花怪
- js中获取匿名函数调用的callee和本js匿名函数中的所有文本内容
- pandaboard Rev b3 刷boot和android系统
- java服务器推送消息技术
- LED行业政府补贴好与不好
- C/C++中static关键字作用总结
- 由Strurts2漏洞引开谈谈web代码安全问题
- HDOJ笔记
- C#命名空间