6つの画像すべてにカスタム画像が入力されたHorizontalUIScrollViewがあるプロジェクトがあります。
UIScrollViewからビューの上部にあるHeaderImageに画像をドラッグアンドドロップすると。ScrollViewから画像をドロップした領域のHeaderimageを変更します。
今の私の課題は、UIScrollViewですべて異なる複数の画像があることですが、UIScrollViewの画像のいずれかをHeaderImage領域にドラッグアンドドロップすると、すべて同じ画像に変わります。
UIImageタグを設定して、UIScrollView画像を設定すると画像が保存され、HeaderImage領域にドロップすると正しい画像または別の画像が表示されるようにするにはどうすればよいですか。
基本的に、ScrollViewのどの画像がドロップされるかに応じてHeaderImageを変更できるようにしたいと思います。
以下は私のコードです:
どんな援助も大歓迎です。
みんなありがとう。私は本当に私に与えられたすべての大きな助けに感謝しています。
GalleryScrollView.mでscrollviewの画像を設定します
- (void) addAttachment:(AttachmentItem *)attachment
{
// SAVE ATTACHMENT
[_attachments addObject:attachment];
// RESIZE CONTENT VIEW FOR INSERTINT NEW ATTACHMENT
_scrollView.contentSize = CGSizeMake([_attachments count]*70, 70);
CGFloat startX = (70.0f * ((float)[_attachments count] - 1.0f) + padding);
CGFloat startY = 370;
CGFloat width = 64;
CGFloat height = 64;
GalleryButton *btnAttachment = [[GalleryButton alloc] initWithFrame:CGRectMake(startX, startY, width, height)];
btnAttachment.tag = [_attachments count];
btnAttachment.scrollParent = _scrollView;
btnAttachment.mainView = self.mainView;
btnAttachment.delegate = self;
if (attachment.type == 1){
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 64, 64)];
imageView.image=[UIImage imageNamed:@"canadian-maple.png"];
[btnAttachment addSubview:imageView];
int tag = btnAttachment.tag;
NSLog(@"%d", tag);
[imageView release];
}else if (attachment.type == 2){
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 64, 64)];
imageView.image=[UIImage imageNamed:@"mozambique-wenge.png"];
[btnAttachment addSubview:imageView];
int tag = btnAttachment.tag;
NSLog(@"%d", tag);
[imageView release];
} else if (attachment.type == 3){
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 64, 64)];
imageView.image=[UIImage imageNamed:@"canadian-maple.png"];
[btnAttachment addSubview:imageView];
int tag = btnAttachment.tag;
NSLog(@"%d", tag);
[imageView release];
}
else if (attachment.type == 4){
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 64, 64)];
imageView.image=[UIImage imageNamed:@"mozambique-wenge.png"];
[btnAttachment addSubview:imageView];
int tag = btnAttachment.tag;
NSLog(@"%d", tag);
[imageView release];
}
else if (attachment.type == 5){
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 64, 64)];
imageView.image=[UIImage imageNamed:@"canadian-maple.png"];
[btnAttachment addSubview:imageView];
int tag = btnAttachment.tag;
NSLog(@"%d", tag);
[imageView release];
}
else if (attachment.type == 6){
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 64, 64)];
imageView.image=[UIImage imageNamed:@"mozambique-wenge.png"];
[btnAttachment addSubview:imageView];
int tag = btnAttachment.tag;
NSLog(@"%d", tag);
[imageView release];
}
[_scrollView addSubview:btnAttachment];
[btnAttachment release];
}
そして、HegakaDragAndDropRecycleBinViewController.mの私のビューにそれらを追加します
- (void)viewDidLoad
{
[super viewDidLoad];
self.gallery.mainView = self.view;
AttachmentItem *item = [[AttachmentItem alloc] initWithData:1 data:nil];
[self.gallery addAttachment:item];
[item release];
AttachmentItem *item2 = [[AttachmentItem alloc] initWithData:2 data:nil];
[self.gallery addAttachment:item2];
[item2 release];
AttachmentItem *item3 = [[AttachmentItem alloc] initWithData:3 data:nil];
[self.gallery addAttachment:item3];
[item3 release];
AttachmentItem *item4 = [[AttachmentItem alloc] initWithData:4 data:nil];
[self.gallery addAttachment:item4];
[item4 release];
AttachmentItem *item5 = [[AttachmentItem alloc] initWithData:5 data:nil];
[self.gallery addAttachment:item5];
[item5 release];
AttachmentItem *item6 = [[AttachmentItem alloc] initWithData:6 data:nil];
[self.gallery addAttachment:item6];
[item6 release];
}
そして、ここにTouchesEndedのアクションを追加します
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if ([delegate isInsideRecycleBin:self touching:YES]){
CGRect myImageRect = CGRectMake(0, 0, 320, 300);
headerImage = [[UIImageView alloc] initWithFrame:myImageRect];
[headerImage setImage:[UIImage imageNamed:@"light-cherry.png"]];
[self.mainView addSubview:headerImage];
UIImageView * animation = [[UIImageView alloc] init];
animation.frame = CGRectMake(self.center.x - 32, self.center.y - 32, 40, 40);
animation.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed: @"iconEliminateItem1.png"],
[UIImage imageNamed: @"iconEliminateItem2.png"],
[UIImage imageNamed: @"iconEliminateItem3.png"],
[UIImage imageNamed: @"iconEliminateItem4.png"]
,nil];
[animation setAnimationRepeatCount:1];
[animation setAnimationDuration:0.35];
[animation startAnimating];
[self.mainView addSubview:animation];
[animation bringSubviewToFront:self.mainView];
[animation release];
;
[UIView beginAnimations:@"goback" context:nil];
[UIView setAnimationDuration:0.4f];
[UIView setAnimationBeginsFromCurrentState:YES];
self.center = _originalOutsidePosition;
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector: @selector(animationDidStop:finished:context:)];
// loadingView.frame = CGRectMake(rect.origin.x, rect.origin.y - 80, rect.size.width, rect.size.height);
[UIView commitAnimations];
} else{
[UIView beginAnimations:@"goback" context:nil];
[UIView setAnimationDuration:0.4f];
[UIView setAnimationBeginsFromCurrentState:YES];
self.center = _originalOutsidePosition;
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector: @selector(animationDidStop:finished:context:)];
// loadingView.frame = CGRectMake(rect.origin.x, rect.origin.y - 80, rect.size.width, rect.size.height);
[UIView commitAnimations];
}
[self.delegate touchUp];
さて、多分私は正しい軌道に乗っています。これが進むべき道なら誰かが私を案内してくれるかもしれないので、私は付け加えました:
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
switch ([delegate isInsideRecycleBin:self touching:YES]) {
case 1:{
CGRect myImageRect = CGRectMake(0, 0, 320, 300);
headerImage = [[UIImageView alloc] initWithFrame:myImageRect];
[headerImage setImage:[UIImage imageNamed:@"mozambique-wenge.png"]];
headerImage.backgroundColor = [UIColor blackColor];
headerImage.layer.borderWidth = 2;
headerImage.layer.borderColor = [UIColor blackColor].CGColor;
headerImage.layer.masksToBounds = YES;
headerImage.layer.cornerRadius = 5;
[self.mainView addSubview:headerImage];
UIImageView * animation = [[UIImageView alloc] init];
animation.frame = CGRectMake(self.center.x - 32, self.center.y - 32, 40, 40);
animation.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed: @"iconEliminateItem1.png"],
[UIImage imageNamed: @"iconEliminateItem2.png"],
[UIImage imageNamed: @"iconEliminateItem3.png"],
[UIImage imageNamed: @"iconEliminateItem4.png"]
,nil];
[animation setAnimationRepeatCount:1];
[animation setAnimationDuration:0.35];
[animation startAnimating];
[self.mainView addSubview:animation];
[animation bringSubviewToFront:self.mainView];
[animation release];
;
[UIView beginAnimations:@"goback" context:nil];
[UIView setAnimationDuration:0.4f];
[UIView setAnimationBeginsFromCurrentState:YES];
self.center = _originalOutsidePosition;
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector: @selector(animationDidStop:finished:context:)];
// loadingView.frame = CGRectMake(rect.origin.x, rect.origin.y - 80, rect.size.width, rect.size.height);
[UIView commitAnimations];
}
break;
case 2:{
CGRect myImageRect = CGRectMake(0, 0, 320, 300);
headerImage = [[UIImageView alloc] initWithFrame:myImageRect];
[headerImage setImage:[UIImage imageNamed:@"recyclebin.png"]];
headerImage.backgroundColor = [UIColor blackColor];
headerImage.layer.borderWidth = 2;
headerImage.layer.borderColor = [UIColor blackColor].CGColor;
headerImage.layer.masksToBounds = YES;
headerImage.layer.cornerRadius = 5;
[self.mainView addSubview:headerImage];
UIImageView * animation = [[UIImageView alloc] init];
animation.frame = CGRectMake(self.center.x - 32, self.center.y - 32, 40, 40);
animation.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed: @"iconEliminateItem1.png"],
[UIImage imageNamed: @"iconEliminateItem2.png"],
[UIImage imageNamed: @"iconEliminateItem3.png"],
[UIImage imageNamed: @"iconEliminateItem4.png"]
,nil];
[animation setAnimationRepeatCount:1];
[animation setAnimationDuration:0.35];
[animation startAnimating];
[self.mainView addSubview:animation];
[animation bringSubviewToFront:self.mainView];
[animation release];
;
[UIView beginAnimations:@"goback" context:nil];
[UIView setAnimationDuration:0.4f];
[UIView setAnimationBeginsFromCurrentState:YES];
self.center = _originalOutsidePosition;
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector: @selector(animationDidStop:finished:context:)];
// loadingView.frame = CGRectMake(rect.origin.x, rect.origin.y - 80, rect.size.width, rect.size.height);
[UIView commitAnimations];
}
}
}
しかし、何も起こりません