我的FYImageSequence.m文件中有这两个函数,我从UIImageView继承了该类
@interface FVImageSequence : UIImageView
我可以将它连接到 Storyboard上的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];
}
最佳答案
默认情况下,UIImageView
的用户交互为否。所以你需要像这样 YES
self.userInteractionEnabled = YES;
关于ios - Touchesbegan和touchesmoved函数在UIImageView上不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20486611/