功能源代碼(扇形進度)及Delegate運用在開放事件中

来源:http://www.cnblogs.com/wujy/archive/2016/06/03/5541770.html
-Advertisement-
Play Games

1:扇形進度視圖及運用 首先先創建扇形的視圖,傳入進度值 運用: 註意:在break裡面要先處理一下對象__weak LHProgressView *progressView = _progressView;上面也用到SDWebImage進行圖片載入,並把進度賦值 2: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)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);
}

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • window window對象不但充當全局作用域,而且表示瀏覽器視窗。 window對象有innerWidth和innerHeight屬性,可以獲取瀏覽器視窗的內部寬度和高度。內部寬高是指除去菜單欄、工具欄、邊框等占位元素後,用於顯示網頁的凈寬高。還有一個outerWidth和outerHeight ...
  • 昨天的《移動 Web 開發技巧》的這篇文章,大家反響不錯,因為這些問題在大家日常寫移動端的頁面時經常遇到的。所以那個文章還是超級實用的,那麼我們今天繼續來分享一下移動端的web開發技巧吧,希望對大家有所幫助。 PS:不要讓小伙伴第一次寫移動端像下麵這位一臉的蒙逼哈哈… … 第一、啟用 WebApp ...
  • 迭代器(iterator)是一個可以順序存取數據集合的對象。其一個典型的API是next方法。該方法獲得序列中的下一個值。 迭代器示例 測試代碼好下: 初步編碼 用上面的測試代碼進行測試 錯誤分析 代碼運行結果並不正確,下麵就對初始的編碼程式進行分析。 這裡的指代錯誤,很像是另一個讓人頭痛的對象th ...
  • 什麼,你現在還在看knockoutjs?這貨都已經落後主流一千年了!趕緊去學Angular、React啊,再不趕緊的話,他們也要變out了哦。身旁的90後小伙伴,嘴裡還塞著山東的狗不理大蒜包,卻依然振振有詞地喋喋不休,一臉真誠。是啊,前端發展太快,那邊前幾年出的框架已是無人問津的半老徐娘,而這邊各種... ...
  • 目錄: TweenMax動畫庫學習(一) TweenMax動畫庫學習(二) 之前在做HTML5移動端開發的時候,用的都是Animate.css,這個插件封裝的的確很好,但是在做一些緩動方面的動畫,它也有一定的不足之處,比如手要寫一個連續的動畫,需要不停的去重覆寫函數,使得代碼嚴重的冗餘,再比如要獲取 ...
  • 完全定製UITabBarViewController 效果 源碼 https://github.com/YouXianMing/iOS-Project-Examples 中的 TotalCustomTabBarController 說明 詳細細節請參考演示項目,定製按鈕需要繼承控制器,在重載buil ...
  • 1.xml activity_main.xml fargment_main.xml list_item_main.xml 2.java MainActivity.java ...
  • iOS應用的安全性 常常被大家忽視。 1、首先,我們可以通過軟體 下載 AppStore的ipa文件(蘋果 把開發者上傳的ipa進行了加殼再放到AppStore中), 得到ipa文件 可以分析APP 里包含的一些資源,如:圖片、plist文件、靜態wap頁、.bundle 等。 所以不要 在plis ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...