私のアプリでは、画像(フォームサーバ)を持つこのUISmageViewsのUIScrollViewが動的にロードされているUIViewが1つあります。私の必要条件は、スクロールビュー画像内の画像をタッチするとUIScrollView画像の上に正確にUIViewで生成する必要があるということです。このため私はUITapGestureRecognizerを使用しています。画像はUIViewで生成されていますが、scrollViewの画像の上に正確には表示されません。 誰でもお勧めします。ビューにおけるUIScrollViewの画像に触れたときにUIViewで画像を生成
負荷iは以下singleTapGestureCaptured方法で動的
- (void)viewDidLoad
{
[super viewDidLoad];
xCordArray = [[NSArray alloc]initWithObjects:@"30",@"78",@"126",@"174", @"222",@"270",@"318",@"366",@"34",@"82",@"130",@"179",@"226",@"274",@"322",@"369",@"38" ,@"88",@"136", @"183",@"248",@"278",@"316",@"375", nil];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapGestureCaptured:)];
[scrollView addGestureRecognizer:singleTap];
[self populateScrollView];
scrollView.delegate = self;
NSMutableArray *getEffectsImageData = [ud objectForKey:@"getimageeffects"];
int scrollViewWidth = [getEffectsImageData count]*48;
[scrollView setContentSize:CGSizeMake(scrollViewWidth, 40)];
}
算出する画像を生成する座標のための1つの静的配列を有していた静的xCordArray値を持つ画像を生成しています。私はこれを動的に生成したい。
- (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture
{
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
NSMutableArray *getEffectsImageData = [ud objectForKey:@"getimageeffects"];
TonifyAppDelegate *appDelegate = (TonifyAppDelegate *)[UIApplication sharedApplication].delegate;
ImageToDrag *img = [[ImageToDrag alloc] init];
for (int i=0; i<[getEffectsImageData count]; i++)
{
UIImageView *ImageView = [imageViewsArray objectAtIndex:i];
NSString *sfxUrlFileName = [[getEffectsImageData objectAtIndex:i] lastPathComponent];
NSLog(@"sfxUrlFileName: %@", sfxUrlFileName);
NSData *imageData = [appDelegate readSongDataFromDocsDirectory:sfxUrlFileName];
UIImage *image = [[UIImage alloc] initWithData:imageData];
CGPoint location = [gesture locationInView:self.scrollView];
int xc = [[xCordArray objectAtIndex:i] intValue];// i want to calculate this xc dynamically.
if(CGRectContainsPoint(ImageView.frame,location))
{
img = [img initWithImage:image];
img.frame = CGRectMake(xc,240, 45, 42);
img.userInteractionEnabled = YES;
[self.view addSubview:img];
img.tag = i;
}
}
}
ありがとうございます。
実装したコードを投稿してください。 –