// // BlindXunlehuiShowView.m // SweetParty // // Created by yons on 2024/12/28. // #import "BlindXunlehuiShowView.h" @interface BlindXunlehuiShowView () @property (nonatomic, assign)CGPoint originalPoint; @end @implementation BlindXunlehuiShowView - (void)awakeFromNib { [super awakeFromNib]; [_leftTimeL styleGradiBlueColor]; UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(onTuodong:)]; [self addGestureRecognizer:pan]; } - (IBAction)onClose:(id)sender { [self removeFromSuperview]; } //滑动事件 - (void)onTuodong:(UIPanGestureRecognizer *)pan{ //获取当前位置 CGPoint currentPosition = [pan locationInView:self]; if (pan.state == UIGestureRecognizerStateBegan) { _originalPoint = currentPosition; }else if(pan.state == UIGestureRecognizerStateChanged){ //偏移量(当前坐标 - 起始坐标 = 偏移量) CGFloat offsetX = currentPosition.x - _originalPoint.x; CGFloat offsetY = currentPosition.y - _originalPoint.y; //移动后的按钮中心坐标 CGFloat centerX = self.center.x + offsetX; CGFloat centerY = self.center.y + offsetY; self.center = CGPointMake(centerX, centerY); } } @end