但这里是我在做什么:
[VIEw setUserInteractionEnabled:YES];[VIEw addTarget:self action:@selector(myAction:) forControlEvents:UIControlEventtouchUpInsIDe];- (voID) myAction:(ID)sender{ NSLog(@"It works!");}解决方法 Objective-C的
在你的vIEwDIDLoad:方法写这个:
-(voID)vIEwDIDLoad { UIImageVIEw *imagevIEw = [[UIImageVIEw alloc]initWithFrame:CGRectMake(100.0,100.0,100.0)]; [imagevIEw setimage:[UIImage imagenamed:@"image.png"]]; [imagevIEw setUserInteractionEnabled:YES]; UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapPing:)]; [singleTap setNumberOfTapsrequired:1]; [imagevIEw addGestureRecognizer:singleTap]; [self.vIEw addSubvIEw:imagevIEw];}
然后调用你的手势方式如下:
-(voID)singleTapPing:(UIGestureRecognizer *)recognizer { NSLog(@"image clicked");}
迅速
overrIDe func vIEwDIDLoad() { super.vIEwDIDLoad() let imageVIEw: UIImageVIEw = UIImageVIEw(frame: CGRectMake(100.0,100.0)) imageVIEw.image = UIImage(named: "image.png") imageVIEw.userInteractionEnabled = true let singleTap: UITapGestureRecognizer = UITapGestureRecognizer(target: self,action: #selector(BaseVC.singleTapPing(_:))) singleTap.numberOfTapsrequired = 1; imageVIEw.addGestureRecognizer(singleTap) self.vIEw.addSubvIEw(imageVIEw)}func singleTapPing(recognizer: UIGestureRecognizer) { print("image clicked")}总结
以上是内存溢出为你收集整理的iphone – UIImageView作为按钮全部内容,希望文章能够帮你解决iphone – UIImageView作为按钮所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)