我正在使用此代码IBAction
来创建一个UIImageView
带有触摸拖动的内部 UIButton
:
-(IBAction) addNewPhoto:(id)sender{
switch ([sender tag]) {
case 0:{
imageMove = [UIImage imageNamed:@"knet.jpg"];
holderView = [[UIView alloc] initWithFrame:CGRectMake(0,0, imageMove.size.width, imageMove.size.height)];
UIImageView *imageview = [[UIImageView alloc] initWithFrame:[holderView frame]];
[imageview setImage:imageMove];
[holderView addSubview:imageview];
UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scale:)];
[pinchRecognizer setDelegate:self];
[holderView addGestureRecognizer:pinchRecognizer];
UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];
[rotationRecognizer setDelegate:self];
[holderView addGestureRecognizer:rotationRecognizer];
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[panRecognizer setDelegate:self];
[holderView addGestureRecognizer:panRecognizer];
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
[tapRecognizer setNumberOfTapsRequired:1];
[tapRecognizer setDelegate:self];
[holderView addGestureRecognizer:tapRecognizer];
[self.view addSubview:holderView];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.5];
[superView setFrame:CGRectMake(0, 0, 320, 550)];
//[holderView setFrame:CGRectMake(0, 0, 320, 550)];
//holderView.alpha = 1;
[UIView commitAnimations];
}
break;
case 1:
{
imageMove = [UIImage imageNamed:@"test.jpg"];
//..........similar to case 0 but another picture
}
break;
default:
break;
}
按钮在 a 内scrollView
,我正在寻找的是,应该在用户将他/她的手指从按钮上拖下来并且仍然能够在不移开他/她的手指的情况下移动它的地方创建图像。
我使用源代码来移动、缩放、旋转这个博客中的图像,并修改了使用按钮而不是 UIImagePickerController 创建图像。