1

スクロールビューから画像を領域にドラッグアンドドロップして、スクロールビューの画像を画像が変更される領域にドロップすると、その領域の画像を変更するアプリケーションがあります。

私の質問は、ヘッダーの画像を領域にドラッグされたものに変更する方法です。

現在、スクロールビューにさまざまな画像があり、それらの画像をすべて、定義した同じ画像が領域にドラッグアンドドロップすると表示されます。

ScrollView 内の画像ごとに異なるドロップ タッチ イベントを作成するにはどうすればよいですか。

ここに画像の説明を入力

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

if ([delegate isInsideRecycleBin:self touching:YES]){

    CGRect myImageRect = CGRectMake(0, 0, 320, 300);
    images = [[UIImageView alloc] initWithFrame:myImageRect];
    [images setImage:[UIImage imageNamed:@"light-cherry.png"]];
    [self.mainView addSubview:images];


    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];


}

上記は、画像がドロップされたイベントのコードです。

以下は、ScrollView Upでボタンを設定する方法です

- (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];
}

- (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];
}

だから今、HeaderImage を変更する領域にドラッグされる画像の配列を作成しようとしましたが、再び立ち往生しました。私は自分のプロジェクトに必要な機能の最後の部分にいます。私がやろうとしているのは、ピックアップされ、ヘッダー画像領域にドラッグ アンド ドロップされた画像に従って、ビューの上部にある HeaderImage を変更することだけです。 .

コード編集

このようなものは機能しますか?

// Create the UIImage's from the images folder
UIImage *app = [UIImage imageNamed:@"Appstorm.jpg"];
UIImage *creat = [UIImage imageNamed:@"Creattica.jpg"];
UIImage *free = [UIImage imageNamed:@"Freelance.jpg"];
UIImage *net = [UIImage imageNamed:@"Netsetter.jpg"];
UIImage *rock = [UIImage imageNamed:@"Rockable.jpg"];
UIImage *tuts = [UIImage imageNamed:@"Tutsplus.jpg"];
UIImage *work = [UIImage imageNamed:@"Workawesome.jpg"];

/* Create the dummy array and fill with the UIImages. */
NSArray *banners = [[NSArray alloc] initWithObjects:app, creat, free, net, rock, tuts, work, nil];

// Set the main images array equal to the dummy array
self.bannerImages = banners;

// Release the dummy array
[banners release];

// Release the UIImage objects
[app release];
[creat release];
[free release];
[net release];
[rock release];
[tuts release];
[work release];

detailVC.banner = [bannerImages objectAtIndex:indexPath.row];

imageView.image = banner;

}

また、画像に画像タグを付けました。これらを使用して、自分がやりたいことを行うにはどうすればよいでしょうか。

4

2 に答える 2

0

Ok。そこで、if else ステートメントを使用してタグを呼び出しました。:)

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if ([delegate isInsideRecycleBin:self touching:YES]){

if (self.tag == 1) {

    NSLog(@"View with tag %i was dropped onto trigger area",self.tag);

    CGRect myImageRect = CGRectMake(0, 0, 320, 300);
    headerImage = [[UIImageView alloc] initWithFrame:myImageRect];
    [headerImage setImage:[UIImage imageNamed:@"light-cherry.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];

}
else if (self.tag == 2)
{

    NSLog(@"View with tag %i was dropped onto trigger area",self.tag);

    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];
}
于 2012-11-15T08:22:58.037 に答える
0

読むべきコードがたくさんあります。スクリーンショットの小さな画像にはカスタム スクロール ビューを使用することをお勧めします。時間を大幅に節約できます

于 2012-11-13T11:33:06.263 に答える