我在FYImageSequence.m文件中有这两个函数。我从UIImageView继承了这个类
@interface FVImageSequence : UIImageView
我能够在故事板中将它连接到我的UIImageView。但是如何使下面的功能工作。是否有任何连接应该完成。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
if(increment == 0)
increment = 1;
[super touchesBegan:touches withEvent:event];
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self];
previous = touchLocation.x;
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesMoved:touches withEvent:event];
UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self];
int location = touchLocation.x;
if(location < previous)
current += increment;
else
current -= increment;
previous = location;
if(current > numberOfImages)
current = 0;
if(current < 0)
current = numberOfImages;
NSString *path = [NSString stringWithFormat:@"%@%d", prefix, current];
NSLog(@"%@", path);
path = [[NSBundle mainBundle] pathForResource:path ofType:extension];
UIImage *img = [[UIImage alloc] initWithContentsOfFile:path];
[self setImage:img];
}
答案 0 :(得分:10)
UIImageView
的用户互动默认为否。所以你需要像这样是
self.userInteractionEnabled = YES;
答案 1 :(得分:2)
在图片视图上将UserInteractionEnabled
设置为YES
。
答案 2 :(得分:0)
为此,我不得不使用方法,而不是变量(不知何时变量不能直接访问),所以:
[self setUserInteractionEnabled:YES];