У меня есть этот код работает отлично, но когда я добавить зум в UIScrollView, я не могу переместить изображение вокруг свитка, изображения не реагирует на событие перетаскиванияПеремещение UIImage вокруг UIScrollView
Что я могу сделать ?
--h file
#import <UIKit/UIKit.h>
@interface DragView : UIImageView
{
CGPoint previousLocation;
}
@end
--m file
#import "DragView.h"
@implementation DragView
- (id) initWithImage: (UIImage *) anImage
{
if (self = [super initWithImage:anImage])
{
self.userInteractionEnabled = YES;
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
self.gestureRecognizers = [NSArray arrayWithObjects:pan,nil];
}
return self;
}
// Promote touched view
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self.superview bringSubviewToFront:self];
previousLocation = self.center;
}
// Move view
- (void) handlePan: (UIPanGestureRecognizer *)uigr
{
CGPoint translation = [uigr translationInView:uigr.view];
uigr.view.center=CGPointMake(uigr.view.center.x+translation.x, uigr.view.center.y+ translation.y);
[uigr setTranslation:CGPointMake(0, 0) inView:uigr.view];
}
@end
А вот использовать Clase для создания образа. с сопротивлением событий
NSMutableArray *arregloImagenes;
DragView *mesas1;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
arregloImagenes=[[NSMutableArray alloc]init];
mesas1 = [[DragView alloc]initWithImage:[UIImage imageNamed:@"mesa.png"]];
mesas1.frame = CGRectMake(0, 0, 50, 50);
[_propVistaCentral addSubview:mesas1];
[_propVistaCentral bringSubviewToFront:mesas1];
_scroll.minimumZoomScale=1;
_scroll.maximumZoomScale=3;
}
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return _propVistaCentral;
}
спасибо, но я нашел решение – Fabio