圆环,扇形控件基本算法一种实现 - 代码库 - CocoaChina_让移动开发更简单
圆环,扇形控件基本算法一种实现 - 代码库 - CocoaChina_让移动开发更简单
//
// CircleCore.h
// Quartz
//
// Created by 仙人掌 on 12-11-5.
// Copyright (c) 2012年 仙人掌. All rights reserved.
//
#import
#define ToRad( degree ) ( degree * M_PI / 180 )
#define ToDeg( rad ) ( rad / M_PI * 180 )
#define ZERO_DEGREE (-90.0f)
typedef enum{
PT_DONE = 0,
PT_UNDONE,
}Path_Type;
typedef struct CircleData{
CGPoint center;
CGFloat radius;
}CircleData;
CircleData CircleDataMake(CGPoint center, CGFloat radius);
CGFloat DistanceBetweenPoints(CGPoint point1,CGPoint point2);
@interface CircleCore : NSObject{
CGFloat referenceDegree_;
CGFloat currentDegree_;
CircleData smallCircle_;
CircleData largeCircle_;
}
@property( nonatomic ) CGFloat referenceDegree;
@property( nonatomic ) CGFloat currentDegree;
@property( nonatomic ) CircleData smallCircle;
@property( nonatomic ) CircleData largeCircle;
-(CGMutablePathRef)GetPathForMode:(Path_Type)pathType;
-(BOOL)PointInPathWithPoint:(CGPoint)point BetweenDegree:(CGFloat)start And:(CGFloat)end;
@end
//-----------------------------------------------------------------------------------------------------------------------------------------------------
//
// CircleCore.m
// Quartz
//
// Created by 仙人掌 on 12-11-5.
// Copyright (c) 2012年 仙人掌. All rights reserved.
//
#import "CircleCore.h"
CircleData CircleDataMake(CGPoint center, CGFloat radius){
CircleData myCircleData;
myCircleData.center = center;
myCircleData.radius = radius;
return myCircleData;
}
CGFloat DistanceBetweenPoints(CGPoint point1,CGPoint point2){
CGFloat temp = ( point1.x - point2.x ) * ( point1.x - point2.x ) + ( point1.y - point2.y ) * ( point1.y - point2.y );
return ( CGFloat )sqrt( temp );
}
@interface CircleCore(Pravite)
-(CGMutablePathRef)GetPathForMode_DONE;
-(CGMutablePathRef)GetPathForMode_UNDONE;
-(CGPoint)GetPointWithCircle:(CircleData)circle AtDegree:(CGFloat)degree;
@end
@implementation CircleCore(Pravite)
-(CGPoint)GetPointWithCircle:(CircleData)circle AtDegree:(CGFloat)degree{
CGFloat x,y;
x = circle.center.x + cos( ToRad( degree ) ) * circle.radius;
y = circle.center.y + sin( ToRad( degree ) ) * circle.radius;
return CGPointMake( x, y );
}
-(CGMutablePathRef)GetPathForMode_DONE{
CGMutablePathRef resultPath = CGPathCreateMutable();
CGPoint smallCircle_referencePoint = [self GetPointWithCircle:smallCircle_ AtDegree:referenceDegree_];
CGPoint largeCircle_referencePoint = [self GetPointWithCircle:largeCircle_ AtDegree:referenceDegree_];
CGPoint smallCircle_currentPoint = [self GetPointWithCircle:smallCircle_ AtDegree:currentDegree_];
CGPathMoveToPoint( resultPath, NULL, smallCircle_referencePoint.x, smallCircle_referencePoint.y );
CGPathAddLineToPoint( resultPath, NULL, largeCircle_referencePoint.x, largeCircle_referencePoint.y );
CGPathAddArc( resultPath, NULL, smallCircle_.center.x, smallCircle_.center.y, largeCircle_.radius, ToRad( referenceDegree_ ), ToRad( currentDegree_ ), 0 );
CGPathAddLineToPoint( resultPath, NULL, smallCircle_currentPoint.x, smallCircle_currentPoint.y );
CGPathAddArc( resultPath, NULL, smallCircle_.center.x, smallCircle_.center.y, smallCircle_.radius, ToRad( currentDegree_ ), ToRad( referenceDegree_ ), 1 );
return resultPath;
}
-(CGMutablePathRef)GetPathForMode_UNDONE{
CGMutablePathRef resultPath = CGPathCreateMutable();
CGPoint largeCircle_referencePoint = [self GetPointWithCircle:largeCircle_ AtDegree:referenceDegree_];
CGPoint smallCircle_currentPoint = [self GetPointWithCircle:smallCircle_ AtDegree:currentDegree_];
CGPathMoveToPoint(resultPath, NULL, largeCircle_referencePoint.x, largeCircle_referencePoint.y);
CGPathAddArc(resultPath, NULL, largeCircle_.center.x, largeCircle_.center.y, largeCircle_.radius, ToRad(referenceDegree_), ToRad(currentDegree_), 1);
CGPathAddLineToPoint(resultPath, NULL, smallCircle_currentPoint.x, smallCircle_currentPoint.y);
CGPathAddArc(resultPath, NULL, smallCircle_.center.x, smallCircle_.center.y, smallCircle_.radius, ToRad(currentDegree_), ToRad(referenceDegree_), 0);
CGPathAddLineToPoint(resultPath, NULL, largeCircle_referencePoint.x, largeCircle_referencePoint.y);
return resultPath;
}
@end
@implementation CircleCore
@synthesize referenceDegree = referenceDegree_;
@synthesize currentDegree = currentDegree_;
@synthesize smallCircle = smallCircle_;
@synthesize largeCircle = largeCircle_;
-(id)init{
self = [super init];
if ( nil != self){
referenceDegree_ = ZERO_DEGREE;
referenceDegree_ = ZERO_DEGREE;
}
return self;
}
-(CGFloat)referenceDegree{
return referenceDegree_ - ZERO_DEGREE;
}
-(void)setReferenceDegree:(CGFloat)referenceDegree{
referenceDegree_ = referenceDegree + ZERO_DEGREE;
}
-(void)setCurrentDegree:(CGFloat)currentDegree{
currentDegree_ = currentDegree + ZERO_DEGREE;
}
-(CGFloat)currentDegree{
return currentDegree_ - ZERO_DEGREE;
}
-(CGMutablePathRef)GetPathForMode:(Path_Type)pathType{
switch (pathType) {
case PT_DONE:
return [self GetPathForMode_DONE];
case PT_UNDONE:
return [self GetPathForMode_UNDONE];
default:
return NULL;
}
}
-(BOOL)PointInPathWithPoint:(CGPoint)point BetweenDegree:(CGFloat)start And:(CGFloat)end{
CGFloat distance = DistanceBetweenPoints( point, largeCircle_.center );
if ( distance > largeCircle_.radius || distance < smallCircle_.radius )
return NO;
CGFloat base_degree = 0.0f;
NSInteger flag = 0;
CGPoint base_point = CGPointMake( point.x - largeCircle_.center.x, largeCircle_.center.y - point.y );
if ( base_point.x >= 0.0f && base_point.y >= 0.0f ){ //第一象限
base_degree = 0.0f;
flag = 1;
}
else if ( base_point.x < 0 && base_point.y >= 0 ){ //第二象限
base_degree = 360.0;
flag = 2;
}
else if ( base_point.x <0 && base_point.y < 0 ){ //第三象限
base_degree = 180.0f;
flag = 3;
}
else{ //第四象限
base_degree = 180.0f;
flag = 4;
}
//
CGFloat x = ABS( base_point.x );
double temp_rad = asin( x / distance );
CGFloat result = 0.0f;
if ( 1 == flag || 3 == flag )
result = ToDeg( temp_rad ) + base_degree;
else
result = base_degree - ToDeg( temp_rad );
if ( result >= start && result <= end )
return YES;
else
return NO;
}
@end
圆环,扇形控件基本算法一种实现 - 代码库 - CocoaChina_让移动开发更简单的更多相关文章
- 屏蔽webbrowser控件右键的一种方法
原文:屏蔽webbrowser控件右键的一种方法 Option ExplicitPrivate Declare Sub ZeroMemory Lib "KERNEL32" Alia ...
- WPF编程,通过Double Animation动态更改控件属性的一种方法。
原文:WPF编程,通过Double Animation动态更改控件属性的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/a ...
- WPF编程,通过【帧】动态更改控件属性的一种方法。
原文:WPF编程,通过[帧]动态更改控件属性的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/article/detail ...
- [转]MFC子线程中更新控件内容的两种办法
一.概述 每个系统中都有线程(至少都有一个主线程),而线程最重要的作用就是并行处理,提高软件的并发率.针对界面来说,还能提高界面的响应能力.一般的,为了应用的稳定性,在数据处理等耗时操作会单独在一个线 ...
- C# WinForm中 让控件全屏显示的实现代码
夏荣全 ( lyout(at)163.com )原文 C#中让控件全屏显示的实现代码(WinForm) 有时候需要让窗口中某一块的内容全屏显示,比如视频播放.地图等等.经过摸索,暂时发现两种可行方法, ...
- Devexpress treelist 树形控件 实现带三种状态的CheckBox
树形控件是使用频率很高的一种控件.对于属性控件往往需要下面两个功能 1.TreeList带有CheckBox,并且节点要有三种状态(所有的子节点都选中,所有的子节点都没选择,一部分子节点选中).使用 ...
- VC 对话框背景颜色、控件颜色(三种方法)
系统环境:Windows 7软件环境:Visual C++ 2008 SP1本次目的:为对话框设置背景颜色.控件颜色 既然MFC对话框不好开发,那么现在我们来开始美化我们的对话框.为对话框设置背景颜色 ...
- C#自动实现Dll(OCX)控件注册的两种方法
尽管MS为我们提供了丰富的.net framework库,我们的程序C#开发带来了极大的便利,但是有时候,一些特定功能的控件库还是需要由第三方提供或是自己编写.当需要用到Dll引用的时候,我们通常会通 ...
- 【Winform-自定义控件】可以使用2种半透明的颜色来填充Button
制作一个自定义按钮,使用2种半透明的颜色来填充Button 1.添加一个自定义控件类,并改变基类,继承自Button public partial class CustomControl1 : But ...
随机推荐
- [转]How to use an Area in ASP.NET Core
本文转自:http://stackoverflow.com/questions/36535511/how-to-use-an-area-in-asp-net-core Q: How does one ...
- [转]oracle中查看用户权限
本文转自:http://www.cnblogs.com/QDuck/archive/2010/08/11/1797225.html 1.查看所有用户: select * from dba_user ...
- JavaScript - 表单提交前预览图片
其实这东西网上到处都是,但并不完整. 正好我也遇到了这个问题,不仅仅是预览,还需要得到图片的属性. 于是东凑西凑整理出一个完整的版本,并根据个人的理解加上了一点点说明. 首先做一些准备工作,HTML方 ...
- MySQL 里的 Timestrap 和 DateTime 和 Java 中的 Date
世界标准时(UTC) 和 格林威治标准时(GMT) 怎么样的时间算是准确的呢?例如这一分种内是60s ,而下一分钟实际走到了59秒的时候却显示一分钟到了,即是时间快了,这样定义为不准确.下面两个解释可 ...
- 一、URL和URLConnection
一.简述: 在Java网络编程中,我们最常听到的一个单词是URL.URL标识了一个资源,并可以通过URL来获取这个资源.我们不知道资源具体是什么,也不需要关心怎么获取.你只需要拿到一个URL,你就可以 ...
- MongoDB 学习(三)MongoDB 和 Spring 整合(Maven)
一.MongoDB 和 Spring 整合(Maven) 1.相关 jar 包准备 2.用 Maven 创建项目,pom.xml 文件 <project xmlns="http://m ...
- 学会Markdown,写博客不愁
前言 Markdown是一种轻量级的标记语言,有John Gruber以及Aaron Hillel Swartz一起编写.Aaron Hillel Swartz是一个极富传奇的黑客,有兴趣可以看看他的 ...
- Java并发编程:volatile关键字解析(学习总结-海子)
博文地址:Java并发编程:volatile关键字解析
- java 生成和解析xml
本文主要使用的是Jdom.jar包(包的下载百度一下)实现了生成xml文件和解析xml文件 下面是生成xml的实现 说明:stuLists集合是一个存放着Student对象的集合 import jav ...
- jquery not() 方法
1.not(expression) 根据表达式参数的值,从包装集里删除元素 example : $('img[alt]').not('[alt*=joy]') 返回包含属性alt的img元素,但img ...