私のアプリでは、この1つのUIScrollViewに1つのUIViewがあり、画像(フォームサーバー)を含むいくつかのUIImageViewがあり、動的に読み込まれます。私の要件は、scrollview画像の画像をタッチすると、UIViewでUIScrollView画像の上部に正確に生成される必要があることです。このために私はUITapGestureRecognizerを使用しています。画像はUIViewで生成されていますが、scrollViewの画像の上部に正確に表示されているわけではありません。誰でも提案に行くのを手伝うことができます。
ビューでは、動的に計算したい画像を生成するための座標用の静的配列が1つあります。
- (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)];
}
次のsingleTapGestureCapturedメソッドでは、静的な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;
}
}
}
前もって感謝します。