I'm trying to pan and zoom into an image. As the pan-gesture isn't available in C4 yet, I thought I could go with a slider for the beginning. So I'm adding the pan-gesture to the photo like this:
-(void)photoToCrop{
photoTaken=[C4Image imageNamed:@"image.jpg"];
photoTaken.height=self.canvas.height;
photoTaken.origin=CGPointMake(0, 0);
[self.canvas addImage:photoTaken];
[self addGesture:PAN name:@"pan" action:@"movePhoto:"];
}
-(void)movePhoto:(UIPanGestureRecognizer *)recognizer {
CGPoint thePoint=[recognizer locationInView:self.view];
//C4Log(@"current position:%f,%f",thePoint.x, thePoint.y);
if (thePoint.x>photoTaken.origin.x &&thePoint.x<photoTaken.origin.x+photoTaken.width && thePoint.y>photoTaken.origin.y &&thePoint.y<photoTaken.origin.y+photoTaken.height) {
C4Log(@"touched inside+moved");
[photoTaken move:recognizer];
}
}
I'm using the pan gesture only when the user actually tabs the image and not anywhere outside (that's the if-statement up there) It works perfectly fine by itself. Then I also have a slider that I attached to scaling the same image:
-(void)sliderSetup{
[self createAddSliderObjects];
zoomSlider.minimumValue=0.52f;
zoomSlider.maximumValue=10.0f;
//scalefactor=1;
zoomSlider.value=1.0f;
}
-(void)createAddSliderObjects{
sliderLabel=[C4Label labelWithText:@"1.0"];
sliderLabel.textColor=navBarColor;
zoomSlider=[C4Slider slider:CGRectMake(0, 0, self.canvas.width-20, 20)];
//positioning
sliderLabel.center=CGPointMake(self.canvas.width/2,self.canvas.height-NavBarHeight-50);
zoomSlider.center=CGPointMake(sliderLabel.center.x,sliderLabel.center.y+10);
//set up action
[zoomSlider runMethod:@"sliderWasUpdated:"
target:self
forEvent:VALUECHANGED];
[self.canvas addObjects:@[sliderLabel, zoomSlider]];
}
-(void)sliderWasUpdated:(C4Slider*)theSlider{
//update the label to reflect current scale factor
sliderLabel.text=[NSString stringWithFormat:@"%4.2f", theSlider.value];
[sliderLabel sizeToFit];
//scale the image
C4Log(@"slider:%f",theSlider.value);
photoTaken.height=self.canvas.height*theSlider.value;
photoTaken.center=self.canvas.center;
}
It also works fine by itself. But trying to use both at the same time doesn't work. In that case only panning the image works, but nothing happens to the slider ever. it seems that it's not getting any triggers ever.... Does someone have a suggestion what else I could try?