美文网首页
智能升降桌—UI界面2

智能升降桌—UI界面2

作者: 我打你吧 | 来源:发表于2016-12-22 16:36 被阅读0次

承接UI界面1:

#pragma mark -  触摸事件执行

- (void)longPressGesture:(UILongPressGestureRecognizer *)longGesture{

BOOL containsPoint=[self containsPoint:[longPressGestureRecognizer locationInView:self]];

NSInteger tag = [self indexOfPoint:[longPressGestureRecognizer locationInView:self]];

if (containsPoint) {

if (!layerArray) {

layerArray=[[NSMutableArray alloc]init];

for (NSDictionary *dic in self.pathArray) {

UIBezierPath *path=[dic objectForKey:PathKey];

CAShapeLayer *maskLayer = [CAShapeLayer layer];

maskLayer.path = [path CGPath];

maskLayer.fillColor = [[UIColor lightGrayColor] CGColor];

[self.layer addSublayer:maskLayer];

[layerArray addObject:maskLayer];  }  }  }

if (longGesture &&(longGesture.state==UIGestureRecognizerStateBegan)) {

if (!containsPoint){

return;     }

if (longGesture.state==UIGestureRecognizerStateBegan) {

longPressNotComplete=YES;

if (longPressAction!=nil) {

//如果有长按执行事件,则初始化timer

longPressTimer=[NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(longPressTimerOut) userInfo:nil repeats:NO];

}   }

[UIVIew animateWithDuraion:0.02 animations:^{

for(NSInter i=0;i<layerArray.count;i++){

CAShapeLayer * layer=[layerArray objectAtIndex:i];

if (i==tag) {

layer.fillColor=[[UIColor lightGrayColor] CGColor];

}else{

layer.fillColor=[[UIColor colorWithWhite:0 alpha:0] CGColor];

}  }  }

}completion:^(BOOL finished) {

switch (tag) {

case 2:  //  点击  3档

[self cricleAnimation:M_PI/3];

break;

case 0:  //  点击 1档

[self cricleAnimation:-M_PI/3];

break;

case 1:  //  点击 2档

[self cricleAnimation:0];

break;

case 4:  //  点击 -档

[saveBut setBackgroundImage:[UIImage imageNamed:@"save_press"] forState:UIControlStateNormal];

saveBut.userInteractionEnabled = YES;

break;

case 3:  //  点击 +档

[saveBut setBackgroundImage:[UIImage imageNamed:@"save_press"] forState:UIControlStateNormal];

saveBut.userInteractionEnabled = YES;

break;

default:

break;   }

}];   }

if (tag == 4) {

if (longGesture.state == UIGestureRecognizerStateBegan) {

[self.delegate controlDeviceDownBegin];   }

if (longGesture.state == UIGestureRecognizerStateEnded ) {

[self.delegate controlDeviceDownEnd];  }   }

if (tag == 3) {

if (longGesture.state == UIGestureRecognizerStateBegan) {

selectTag = 3;

[self.delegate controlDeviceUpBegin];    }

if (longGesture.state == UIGestureRecognizerStateEnded ) {

[self.delegate controlDeviceUpEnd];   }  }

if (longGesture.state==UIGestureRecognizerStateEnded||longGesture==nil) {

[UIView animateWithDuration:0.3 animations:^{

for (CAShapeLayer *layer in layerArray) {

layer.fillColor=[[UIColor colorWithWhite:0 alpha:0] CGColor];;   }    }];

if (longGesture.state==UIGestureRecognizerStateEnded) {

if (longPressTimer) {

[longPressTimer invalidate];    }   }   }

if (containsPoint && longGesture.state==UIGestureRecognizerStateEnded&&longPressNotComplete) {

if (handel&&[handel respondsToSelector:touchAction ]) {

self.selectButtonPosition=[self GetPositonWithTag:tag];

[handel performSelector:touchAction withObject:self afterDelay:0];

}   }

if(containsPoint && longGesture==nil) {

if (handel&&[handel respondsToSelector:longPressAction ]) {

NSInteger tag = [self indexOfPoint:[longPressGestureRecognizer locationInView:self]];

self.selectButtonPosition=[self GetPositonWithTag:tag];

[handel performSelector:longPressAction withObject:self afterDelay:0];

}   }  }

#pragma mark - 获取位置

-(SelectButtonPosition)GetPositonWithTag:(NSInteger)tag{

NSDictionary *path=[self.pathArray objectAtIndex:tag];

return [[path objectForKey:PositionKey] intValue];

}

#pragma mark - 点是否在曲线内

-(BOOL)containsPoint:(CGPoint)point{

return ([self indexOfPoint:point]==-1?NO:YES);

}

#pragma mark - 获取获取点在数组的位置

-(NSInteger)indexOfPoint:(CGPoint)point{

for (NSDictionary *path in self.pathArray) {

if ([[path objectForKey:PathKey] containsPoint:point]) {

return  [self.pathArray indexOfObject:path];

break;  }  }

return -1;  }

#pragma mark - 长按1.5s后执行

-(void)longPressTimerOut{

longPressNotComplete=NO;

[longPressTimer invalidate];

[self longPressGesture:nil];

}

ok,到这里,这个界面完成了,本来想发到git,想想还是没发。感觉以后智能家居以后会是一个小热点,跟小友分享。

相关文章

网友评论

      本文标题:智能升降桌—UI界面2

      本文链接:https://www.haomeiwen.com/subject/cphhvttx.html