- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 iOS 新手,我对 setUserInteractionEnabled
有疑问: 我有一个从 UIImageView 扩展的对象,例如:
@interface CustomImageView : UIImageView
@property (retain, nonatomic) NSString *sNameImage;
@property (retain, nonatomic) NSString *sID;
@property (assign, nonatomic) float nPointX;
@property (assign, nonatomic) float nPointY;
-(void)setPoint:(NSString *)sPoint;
然后当我将它添加到 UIView 时:
for(int i = 0; i < self.arrCustomImageView.count; i++)
{
CustomImageView *cuiv = [self.arrCustomImageView objectAtIndex:i];
NSData *data = [self readDataFromFile:cuiv.sNameImage];
if(data != nil && data.length > 0)
{
UIImage *image = [[UIImage alloc] initWithData:data];
CGRect r = CGRectMake(cuiv.nPointX, cuiv.nPointY, image.size.width, image.size.height);
[cuiv setUserInteractionEnabled:FALSE]; /*or NO i tried all*/
[cuiv setImage:image];
cuiv.frame = r;
[self addSubview:cuiv];
[image release];
image = nil;
}
}
然后在 touchesBegan
中,我仍然在触摸它时捕获事件(触摸它时我仍然收到日志):|
然后源码touchBegan方法:
UITouch * touch = [touches anyObject];
for (UIView *aView in [self subviews])
{
if (CGRectContainsPoint([aView frame], [touch locationInView:self]))
{
self.imvChoice = (CustomImageView *) aView;
originalPoint = aView.frame.origin;
offsetPoint = [touch locationInView:aView];
nIndexChoice = [self.arrCustomImageView indexOfObject:aView];
NSLog(@"log: %@ >> %@: id: %d", NSStringFromClass([self class]),NSStringFromSelector(_cmd), nIndexChoice);
[self bringSubviewToFront:aView];
}
}
我不认为这是问题,因为我已经尝试添加相同的 UIImageView,如下所示:
for(int i = 0; i < [arrObject count]; i++)
{
CustomObject *nsObj = [arrObject objectAtIndex:i];
UIImageView *image1 = [self createUIImageView:[nsObj sName1] pointX:nsObj.pPoint1.x pointY:nsObj.pPoint1.y];
image1.tag = i;
[image1 setUserInteractionEnabled:FALSE];
UIImageView *image2 = [self createUIImageView:[nsObj sName2] pointX:nsObj.pPoint2.x pointY:nsObj.pPoint2.y];
image2.tag = i;
[image2 setUserInteractionEnabled:TRUE];
[self addSubview:image1];
[self addSubview:image2];
[image1 release];
[image2 release];
}
它运行正常:|单击 image1 时我无法捕获事件,而 image2 可以。
所以我错了?请帮我解释一下!感谢大家的支持!
最佳答案
touchesBegan
接收整个 View Controller 的触摸,而不仅仅是单个 uiview。如果您将 userInteractionEnabled
设置为 false,则该 View 将不会收到任何特定于 View 的事件,例如 UITouchUpInside
。
如果你想检查你的 touchesBegan
方法,如果用户点击了一个“禁用”的对象,你必须获得用户触摸你的 ViewController 的坐标,例如像这样
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchPoint = [touch locationInView:self.view];
然后检查您的触摸点是否在您要检查的 View 对象的矩形内
if (CGRectContainsPoint(cuiv, touchPoint){
if (cuiv.userInteractionEnabled) {
// your element is enabled, do something
} else {
// your element is disabled, do something else
}
}
关于ios - 关于 iOS 中的 setUserInteractionEnabled UIImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23626305/
我有一个名为 SplashViewController 的 UIViewController 实例。我将它添加到 AppDelegate 的主窗口中,如下所示: splashViewControlle
我想使 UIButton 禁用用户触摸。 setEnabled 和setUserInteractionEnabled 都可以做到这一点。哪个更好?它们有何不同? 最佳答案 enabled 是 UICo
我是 iOS 新手,我对 setUserInteractionEnabled 有疑问: 我有一个从 UIImageView 扩展的对象,例如: @interface CustomImageView :
等等!!!: 我知道您可能认为这个问题已经被问过并回答过好几次了。但我可以保证你这个问题是独一无二的。 问题: 在 iOS 应用程序中,想象一下有两个按钮,如下图所示,它们有两个 Action ,就像
我是一名优秀的程序员,十分优秀!