扇形进度

1:扇形进度视图及运用

首先先创建扇形的视图,传入进度值

#import <UIKit/UIKit.h>

@interface LHProgressView : UIView

@property (nonatomic) float progress;

@end
#import "LHProgressView.h"
#define MinProgress (1.0 / 16.0)

@implementation LHProgressView

- (id)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor clearColor];
        _progress = MinProgress;
    }
    return self;
}

- (void)drawRect:(CGRect)rect
{

    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextFillPath(context);
    CGRect aRect= CGRectMake(2, 2, self.bounds.size.width - 4, self.bounds.size.height - 4);
    CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 0.9);
    CGContextSetLineWidth(context, 2.0);
    CGContextAddEllipseInRect(context, aRect);
    CGContextDrawPath(context, kCGPathStroke);

    CGFloat centerX = self.bounds.size.width / 2;
    CGFloat centerY = self.bounds.size.height / 2;

    UIColor *aColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.9];
    CGContextSetFillColorWithColor(context, aColor.CGColor);
    CGContextSetLineWidth(context, 0.0);
    CGContextMoveToPoint(context, centerX, centerY);
    CGContextAddArc(context, centerX, centerY, (self.bounds.size.width - 10) / 2,  - M_PI_2, - M_PI_2 + self.progress * 2 *M_PI, 0);
    CGContextClosePath(context);
    CGContextDrawPath(context, kCGPathFillStroke);

}

- (void)setProgress:(float)progress
{
    _progress = progress;

    if (_progress < MinProgress) {
        _progress = MinProgress;
    }

    if (_progress >= 1.0) {

        [self setNeedsDisplay];
        [self removeFromSuperview];

    } else {

        [self setNeedsDisplay];

    }

}

@end

运用:

@property(nonatomic, strong)LHProgressView *progressView;
-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {

        self.backgroundColor = [UIColor clearColor];

        _progressView = [[LHProgressView alloc] init];

    }

    return self;
}
- (void)setItemImageUrl:(NSString *)itemImageUrl
{
    _itemImageUrl = itemImageUrl;

    BOOL imageExist = [[SDWebImageManager sharedManager] cachedImageExistsForURL:[NSURL URLWithString:itemImageUrl]];

    if (_itemImageProgress == 1.0 || imageExist) {

        [_progressView removeFromSuperview];

    } else {

        _progressView.bounds = CGRectMake(0, 0, 50, 50);
        _progressView.center = CGPointMake((self.bounds.size.width) / 2, (self.bounds.size.height) / 2);
        [self addSubview:_progressView];

        _progressView.progress = _itemImageProgress;

    }

    _itemImageView.image = _itemImage;

    [self resetSize];

    __weak LHProgressView *progressView = _progressView;
    __weak LHPhotoView *photoView = self;
    NSInteger index = self.tag - 1;

    [[SDWebImageManager sharedManager] downloadImageWithURL:[NSURL URLWithString:itemImageUrl] options:SDWebImageRetryFailed | SDWebImageLowPriority progress:^(NSInteger receivedSize, NSInteger expectedSize) {

        if ([photoView.photoViewDelegate respondsToSelector:@selector(photoIsShowingPhotoViewAtIndex:)]) {
            BOOL isShow = [photoView.photoViewDelegate photoIsShowingPhotoViewAtIndex:index];

            if (isShow) {
                if (receivedSize > kMinProgress) {
                    progressView.progress = (float)receivedSize/expectedSize;
                }
            }

        }

        if ([photoView.photoViewDelegate respondsToSelector:@selector(updatePhotoProgress:andIndex:)]) {
            [photoView.photoViewDelegate updatePhotoProgress:(float)receivedSize/expectedSize andIndex:index];
        }

    } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {

        if (image) {
            if ([photoView.photoViewDelegate respondsToSelector:@selector(photoIsShowingPhotoViewAtIndex:)]) {
                BOOL isShow = [photoView.photoViewDelegate photoIsShowingPhotoViewAtIndex:index];

                if (isShow) {
                    photoView.itemImageView.image = image;

                    [self resetSize];
                }

            }

            if ([photoView.photoViewDelegate respondsToSelector:@selector(updatePhotoProgress:andIndex:)]) {
                [photoView.photoViewDelegate updatePhotoProgress:1.0 andIndex:index];
            }
        }

    }];

}

注意:在break里面要先处理一下对象__weak LHProgressView *progressView = _progressView;上面也用到SDWebImage进行图片加载,并把进度赋值

2:Delegate运用在开放事件中

#import <UIKit/UIKit.h>
@class DMDropDownMenu;

@protocol DMDropDownMenuDelegate <NSObject>

- (void)selectIndex:(NSInteger)index AtDMDropDownMenu:(DMDropDownMenu *)dmDropDownMenu;

@end
@interface DMDropDownMenu : UIView

@property(nonatomic,assign)id<DMDropDownMenuDelegate>delegate;

@end
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self tapAction];
    _curText.text = self.listArr[indexPath.row];
    if ([_delegate respondsToSelector:@selector(selectIndex:AtDMDropDownMenu:)]) {
        [_delegate selectIndex:indexPath.row AtDMDropDownMenu:self];
    }
}

运用时三步代码:

@interface ViewController ()<DMDropDownMenuDelegate>
@end

    DMDropDownMenu * dm1 = [[DMDropDownMenu alloc] initWithFrame:CGRectMake(10, 150, 299, 30)];
    dm1.delegate = self;
    [self.view addSubview:dm1];

- (void)selectIndex:(NSInteger)index AtDMDropDownMenu:(DMDropDownMenu *)dmDropDownMenu
{
    NSLog(@"dropDownMenu:%@ index:%d",dmDropDownMenu,index);
}
时间: 2025-01-03 01:15:38

扇形进度的相关文章

扇形进度条的应用(冷却的技能效果)

使用进度条动作制作冷却的技能效果 扇形进度条的应用 1 /////////// 冷却的技能效果 //////////////////// 2 3 4 // 执行的动作,进度条的动作 5 // 参数(时间,完成度(100:表示全部显示)) 6 ProgressTo *progressTo = ProgressTo::create(5.0f, 100); // 从 0 开始运动 7 // 表示是从 _% 到 _% 显示 8 //ProgressFromTo *progressFromTo = Pro

功能源代码(扇形进度)及Delegate运用在开放事件中

1:扇形进度视图及运用 首先先创建扇形的视图,传入进度值 #import <UIKit/UIKit.h> @interface LHProgressView : UIView @property (nonatomic) float progress; @end #import "LHProgressView.h" #define MinProgress (1.0 / 16.0) @implementation LHProgressView - (id)initWithFra

Quartz2d (画线 矩形 圆 三角形 弧线 扇形 进度圈等)

</pre><pre code_snippet_id="1675698" snippet_file_name="blog_20160509_1_1489477" name="code" class="objc">/** Quartz2d的图形绘制API */ "[画线drawLine]" 1.获取上下文件UIGraphicsGetCurrentContext(); 2.设置起点CGC

1.CCProgressTo进度动作,条形进度条,扇形进度条

 1 Bar形进度 CCSprite * proBack = CCSprite::create("barback.png"); proBack->setPosition(ccp(winSize.width/2 - 100,winSize.height/2)); addChild(proBack); CCProgressTimer * left = CCProgressTimer::create(CCSprite::create("bar.png")); l

CCProgressAction进度条动作的使用(扇形和条形)

CCProgressAction进度条动作的使用(扇形和条形) 扇形进度条的使用:ProgressTo, ProgressFromTo, ProgressTimer 的使用 1 ///////// 扇形进度条的使用 //////////////////// 2 3 // 执行的动作,进度条的动作 4 // 参数(时间,完成度(100:表示全部显示)) 5 ProgressTo *progressTo = ProgressTo::create(5.0f, 100); // 从 0 开始 6 //P

Cocos2d-x学习笔记(14)(更新函数scheduleUpdate、进度计时器CCProgressTo、滚动视图CCScrollView)

一.scheduleUpdate 1.scheduleUpdate:此函数是CCNode的函数,每一个CCNode仅仅要调用scheduleUpdate更新函数,那么这个CCNode就会响应当前类的update(float dt)函数. 首先在头文件里定义update函数:void update(float dt): 接下来在cpp文件里的初始化函数调用scheduleUpdate()函数: 实现update更新函数. 2.schedule:其作用于scheduleUpdate()函数同样,可是

9个绚丽多彩的HTML5进度条动画赏析

进度条在网页应用中越来越广泛了,特别是现在的页面异步局部刷新时代,进度条可以让用户更好的等待操作结果.本文要分享9款绚丽多彩的HTML5进度条动画,有很多还是挺实用的,效果也非常不错. 1.CSS3发光进度条动画 超炫酷的样式 这次我们要来分享一款非常炫酷的CSS3进度条动画,其样式风格类似于星球大战里面的那些激光剑效果.页面初始化时,可以设定进度条的值,但是我们也可以利用其配套的借口来动态改变进度条的值,使用起来比较方便.另外以前介绍过一款CSS3 3D进度条,其风格也类似. 在线演示 源码下

iOS项目开发实战——自定义圆形进度提示控件

iOS中默认的进度条是水平方向的进度条,这往往不能满足我们的需求.但是我们可以自定义类似的圆形的进度提示控件,主要使用iOS中的绘图机制来实现.这里我们要实现一个通过按钮点击然后圆形进度提示不断增加的效果. (1)新建一个Cocoa Touch Class,注意要继承自UIView.这个是绘制图形的类,绘制一个圆形的背景和扇形的进度.具体实现如下: import UIKit class ProgressControl: UIView { override init(frame: CGRect)

cocos2dx基础篇(23)——进度条CCProgressTimer

[唠叨] 哎,周围的同学都在搞cocos2dx 3.X了,而我还在用2.2.3.没办法,网上3.X的教程毕竟很少,还是等我的同学学得差不多了,我再换成3.X跟着同学搞,哪里不会问哪里. 本节主要来讲讲进度条CCProgressTimer,相信大家也不会陌生的吧.如安装软件时显示的进度.游戏中人物的HP.MP显示的百分比横条. [致谢] http://gl.paea.cn/contents/2260d48c5e2bc83d.html (没错,又是这位大牛...) [CCProgressTimer]