我有两个按钮添加图像和编辑。从添加图像即时添加来自图库的多个图像,并且可以在视图中移动每个图像视图。我制作了一个 Draggable 类来移动每个图像视图。
@interface Draggable : UIImageView {
AppDelegate *objectDelegate;
CGPoint startLocation;
}
@property (nonatomic,retain) AppDelegate *objectDelegate;
@end
@implementation Draggable
@synthesize objectDelegate;
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
// Retrieve the touch point
objectDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
CGPoint pt = [[touches anyObject] locationInView:self];
startLocation = pt;
[[self superview] bringSubviewToFront:self];
}
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
// Move relative to the original touch point
CGPoint pt = [[touches anyObject] locationInView:self];
CGRect frame = [self frame];
frame.origin.x += pt.x - startLocation.x;
frame.origin.y += pt.y - startLocation.y;
[self setFrame:frame];
}
@end
以及我添加图像的方式。
UIImage* image = [[UIImage alloc] init];
image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
CGRect cellRectangle;
cellRectangle = CGRectMake(20 ,50,image.size.width/6 ,image.size.height/6 );
//[[self view] addSubview:blockView];
UIImageView *dragger = [[Draggable alloc] initWithFrame:cellRectangle];
[dragger setImage:image];
[dragger setUserInteractionEnabled:YES];
[self.view addSubview:dragger];
现在在“编辑”按钮上,我想将该特定图像编辑为通过单击选择的 b。就像我有 3 张图片 picOne、picTwo 和 picThree。如果我触摸 picTwo 并单击编辑,我希望 picTwo 进行编辑(打开 aviary 编辑器)。
我所做的就是在 Draggable touches 开始时添加了这一行
UITouch *touch = [touches anyObject];
if ([touch view] == objectDelegate.selectedImageViewFromCanvas)
{
// selestecImageViewFromCanvas is UiImageView.
NSLog(@"dragger");
}
但这种说法总是错误的。我希望每个人都能得到我想要的。谢谢