#import "ViewController.h"
//引入第三方框架
#import "MBProgressHUD+ZJ.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *fuzhi;
@property (nonatomic,strong) UIPasteboard *pasteboard;
@end
@implementation ViewController
//懶加載粘貼對(duì)象
- (UIPasteboard *)pasteboard{
if (_pasteboard != nil) return _pasteboard;
_pasteboard = [UIPasteboard generalPasteboard];
NSLog(@"%@",_pasteboard);
return _pasteboard;
}
- (void)viewDidLoad {
[super viewDidLoad];
//打開(kāi)交互界面
self.fuzhi.userInteractionEnabled = YES;
//創(chuàng)建長(zhǎng)按手勢(shì)對(duì)象
UILongPressGestureRecognizer *tapGesture =[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(onClickUILable:)];
//為label添加手勢(shì)對(duì)象
[self.fuzhi addGestureRecognizer:tapGesture];
}
//長(zhǎng)按label調(diào)用的方法
-(void)onClickUILable(UILongPressGestureRecognizer *)sender{
//判斷手勢(shì)的狀態(tài)
if (sender.state == UIGestureRecognizerStateBegan) {
//長(zhǎng)按手勢(shì)開(kāi)始
self.pasteboard.string =self.fuzhi.text;
}else if (sender.state == UIGestureRecognizerStateEnded){
//長(zhǎng)按手勢(shì)結(jié)束
if (self.pasteboard == nil) {
[MBProgressHUD showError:@"復(fù)制失敗"];
} else {
[MBProgressHUD showSuccess:@"已復(fù)制"];
}
}
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者