您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關ios如何實現可拖動按鈕的內容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。
代碼:
- (UIButton *)panButton { if (!_panButton) { UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)]; _panButton = [[UIButton alloc] init]; _panButton.backgroundColor = [UIColor blueColor]; _panButton.layer.borderWidth = 1.f; _panButton.layer.borderColor = [UIColor greenColor].CGColor; [_panButton setTitle:@"清除緩存" forState:UIControlStateNormal]; _panButton.titleLabel.font = [UIFont systemFontOfSize:9]; [_panButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside]; [_panButton addGestureRecognizer:panGesture]; } return _panButton; } - (void)panAction:(UIPanGestureRecognizer *)recognizer { CGPoint translationPoint = [recognizer translationInView:self.view]; CGPoint center = recognizer.view.center; recognizer.view.center = CGPointMake(center.x + translationPoint.x, center.y + translationPoint.y); [recognizer setTranslation:CGPointZero inView:self.view]; } -(void)buttonAction:(UIButton *)sender { NSLog(@"煩人,點我干啥~"); }
感謝各位的閱讀!關于“ios如何實現可拖動按鈕”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。