5 iphone objective-c uiimageview ios
我在我的FYImageSequence.m文件中有这两个函数.我从UIImageView继承了这个类
@interface FVImageSequence : UIImageView
Run Code Online (Sandbox Code Playgroud)
我能够在故事板中将它连接到我的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];
}
Run Code Online (Sandbox Code Playgroud)
Dha*_*ngh 10
用户交互UIImageView默认为NO.所以,你需要使它是这样的
self.userInteractionEnabled = YES;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6227 次 |
| 最近记录: |