智能升降桌—UI界面1

智能升降桌的操作界面

最近在寫智能升降桌的項目,項目中最難的應(yīng)該是操作界面的繪制和硬件數(shù)據(jù)交互,今天我給小友們說一下思路和部分代碼。

上面的操作界面是由兩張圖片組成的,但是點擊的效果是用UIBezierPath和CAShapeLayer繪制的,正好覆蓋每一個按鈕,對了,看到上面那個大大的數(shù)字0了嗎?那是新加的字體庫,在這里順便簡書一下添加一個新的字體:

添加新的字體

下面廢話不多說上代碼:

Controller.m中:

//? 操作view

ControDeviceBut *controVc = [[ControDeviceBut alloc] initWithFrame:CGRectMake((screenWidth-ViewHeight(200))/2, (CGRectGetHeight(self.view.frame)-ViewHeight(350))/2+ViewHeight(180) ,ViewHeight(200), ViewHeight(200)) ButtonType:ButtonType_Round];

[controVc addTarget:self action:@selector(buttonClick:) forResponseState:ButtonClickType_TouchUpInside];

//? ? [controVc addTarget:self action:@selector(longPressButtonClick:) forResponseState:ButtonClickType_LongPress];

controVc.delegate = self;

[self.view addSubview:controVc];

#pragma mark -? 按鈕單擊事件

-(void)buttonClick:(ControDeviceBut *)button{

}

在ControDeviceBut.h中:

typedef enum ButtonType{

/**

*? 圓形五個按鈕 上下左右 中心

*/

ButtonType_Round=0,

}ButtonType;

typedef enum ButtonClickType

{

//手勢抬起響應(yīng)

ButtonClickType_TouchUpInside=0,

//長按0.5s響應(yīng)

ButtonClickType_LongPress,

}ButtonClickType;

typedef enum SelectButtonPosition{

SelectButtonPosition_Top3 =1,

SelectButtonPosition_Top2 =1<<1 ,

SelectButtonPosition_Top1 =1<<2 ,

SelectButtonPosition_Relase =1<<3,

SelectButtonPosition_Add =1<<4,

}SelectButtonPosition;

@interface ControDeviceBut : UIImageView

{

NSMutableArray *layerArray;

SEL? touchAction;

SEL? longPressAction;

id? handel;

UIGestureRecognizerState responseState;

ButtonType buttonType;

UILabel *titleLabel;

NSTimer *longPressTimer;

UILongPressGestureRecognizer *longPressGestureRecognizer;

//長按手勢未執(zhí)行

BOOL longPressNotComplete ;

}

/** *? 獲取選中位置 */@property (nonatomic) enum SelectButtonPosition selectButtonPosition;

@property (weak,nonatomic)iddelegate;

-(instancetype)initWithFrame:(CGRect)frame ButtonType:(ButtonType)type;

-(void)addTarget:(id)target action:(SEL)action forResponseState:(ButtonClickType)state;

/**

*? 設(shè)置響應(yīng)位置,

*? @param position 可以傳多個參數(shù)

*/

-(void)setResponsePosition:(SelectButtonPosition)position;

在ControDeviceBut.m中:

#define PathKey @"path"

#define PositionKey @"position"

#define PathDic(path,position) [NSDictionary dictionaryWithObjectsAndKeys:path,@"path",position,@"position", nil]

#define OffSet 2.5

@interface ControDeviceBut(){

NSInteger selectTag;

UIButton *saveBut;

}

@property (nonatomic) NSMutableArray *pathArray;

@property (nonatomic,strong)UIImageView *controButImg;

@end

@implementation ControDeviceBut

-(instancetype)initWithFrame:(CGRect)frame ButtonType:(ButtonType)type{

self=[super initWithFrame:frame];

if (!self) {

return nil; ? }

self.userInteractionEnabled=YES;

longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressGesture:)];

longPressGestureRecognizer.minimumPressDuration=0.05;

longPressGestureRecognizer.allowableMovement = 10;

longPressGestureRecognizer.delegate = self;

[self addGestureRecognizer:longPressGestureRecognizer];

[self creatUI];

return self; ?}

-(void)create{

//自定義界面

?}

// ?如果界面有button

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {

if ([touch.view isKindOfClass:[UIButton class]]){

return NO; ? }

return YES; ? }

#pragma mark - 添加響應(yīng)事件

-(void)addTarget:(id)target action:(SEL)action forResponseState:(ButtonClickType)state{

handel=target;

switch (state) {

case ButtonClickType_LongPress:

longPressAction=action;

break;

case ButtonClickType_TouchUpInside:

touchAction=action;

break;

default:

break;

}

}

#pragma mark - 設(shè)置響應(yīng)位置

-(void)setResponsePosition:(SelectButtonPosition)position{

if (!_pathArray) {

_pathArray=[[NSMutableArray alloc]init];

}else{

[_pathArray removeAllObjects];

}

if (buttonType==ButtonType_Round) {

if (position & SelectButtonPosition_Top3) {

[_pathArray addObject:[self roundShapWithPosition:SelectButtonPosition_Top3]];

}

if (position & SelectButtonPosition_Top2) {

[_pathArray addObject:[self roundShapWithPosition:SelectButtonPosition_Top2]];

}

if (position & SelectButtonPosition_Top1) {

[_pathArray addObject:[self roundShapWithPosition:SelectButtonPosition_Top1]];

}

if (position & SelectButtonPosition_Relase) {

[_pathArray addObject:[self roundShapWithPosition:SelectButtonPosition_Relase]];

}

if (position & SelectButtonPosition_Add) {

[_pathArray addObject:[self roundShapWithPosition:SelectButtonPosition_Add]];

} ? } ? ?}

#pragma mark - 圓弧貝塞爾曲線

-(NSDictionary *)roundShapWithPosition:(SelectButtonPosition)position{

float radius=CGRectGetWidth(self.frame)/2.0-ViewHeight(7);? //? 顯示點擊顏色的圓半徑

float width=radius-CGRectGetWidth(self.controButImg.frame)/2;? //內(nèi)圓白色

int positionTag=log2(position);

CGPoint center=CGPointMake(CGRectGetWidth(self.frame)/2, CGRectGetHeight(self.frame)/2);

UIBezierPath* bezierPath = [UIBezierPath bezierPath];

float startAngle;

float endAngle;

if (position == SelectButtonPosition_Top1 || position == SelectButtonPosition_Top2 || position == SelectButtonPosition_Top3) {

startAngle = M_PI + positionTag*M_PI/3;

endAngle = startAngle + M_PI/3;

}else if(position == SelectButtonPosition_Relase){

startAngle = 0;

endAngle = startAngle+M_PI/2;

}else{

startAngle = M_PI/2;

endAngle = startAngle+M_PI/2; ? ? }

[bezierPath addArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle clockwise:YES];

[bezierPath addArcWithCenter:center radius:radius-width startAngle:endAngle endAngle:startAngle clockwise:NO];

[bezierPath closePath];

return PathDic(bezierPath, [NSNumber numberWithInteger:position]);

}

#pragma mark - 獲取路徑數(shù)組

-(NSMutableArray *)pathArray{

if (!_pathArray) {

_pathArray=[[NSMutableArray alloc]init];

[_pathArray addObject:[self roundShapWithPosition:SelectButtonPosition_Top3]];

[_pathArray addObject:[self roundShapWithPosition:SelectButtonPosition_Top2]];

[_pathArray addObject:[self roundShapWithPosition:SelectButtonPosition_Top1]];

[_pathArray addObject:[self roundShapWithPosition:SelectButtonPosition_Relase]];

[_pathArray addObject:[self roundShapWithPosition:SelectButtonPosition_Add]]; ? }

return _pathArray; ? }

好像就只能寫這么多字了,,請看下面——UI界面2

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Quartz2D以及drawRect的重繪機制字數(shù)1487 閱讀21 評論1 喜歡1一、什么是Quartz2D Q...
    PurpleWind閱讀 917評論 0 3
  • #define kBlackColor [UIColor blackColor] //.h //劃線 + (voi...
    CHADHEA閱讀 862評論 0 1
  • 前言 起因呢,是在X論壇看到一個動畫,感了興趣,大概講的是一個自行車沿著路移動,路徑大概是下圖。 我下載了作者開源...
    NSNil閱讀 724評論 0 0
  • 1、改變 UITextField 占位文字 顏色和去掉底部白框 [_userName setValue:[UICo...
    i_MT閱讀 1,185評論 0 2
  • 婚姻家庭中,婚外情對女人的傷害似乎遠大于男人。對于很多的女性來說,婚外情是她們放縱自己,發(fā)泄自己的最好途徑。那么,...
    陌上花開jing閱讀 607評論 0 0

友情鏈接更多精彩內(nèi)容