0
안녕하세요, 이미지에 uiscrollview가 채워져 있지만 (코드가 우둔함) 이미지 내부에 이벤트를 추가하는 방법을 모르겠습니다. scrollview 내부의 이미지를 두 번 탭하고 이벤트를 얻고 싶습니다. 어떤 방향으로 이것을 달성하는 방법?이미지에서 uiscrollview 내부의 이벤트를 catch하는 방법
arrayOfImages = [[NSMutableArray alloc] init];
NSString *img;
for (img in imgArray)
{
[arrayOfImages addObject:[UIImage imageNamed:img]];
}
NSLog(@"Array initialization complete...");
scrollView = [[UIScrollView alloc] init];
scrollView.scrollEnabled = YES;
scrollView.pagingEnabled = YES;
scrollView.directionalLockEnabled = YES;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.delegate = self;
scrollView.backgroundColor = [UIColor blueColor];
scrollView.autoresizesSubviews = YES;
scrollView.frame = CGRectMake(0, 0, 320, 29);
[self.view addSubview:scrollView];
NSLog(@"Scroll View initialization setup complete...");
UIImage *imageToAdd;
int x = 0;
int y = 0;
for (imageToAdd in arrayOfImages)
{
UIImageView *temp = [[UIImageView alloc] initWithImage:imageToAdd];
temp.frame = CGRectMake(x, y, 29, 29);
x += 29;
[scrollView addSubview:temp];
}
NSLog(@"Adding images to outlet complete...");
하지만 iCodeBlog에 따르면 uiimageview는 탭을 얻지 못하므로 uiimageview를 다른 uiview로 가져 가야 할 수도 있습니다. – harshalb
지금 추가했습니다. UIImageView * temp = [[UIImageView alloc] initWithImage : imageToAdd]; \t \t \t \t \t \t temp.frame = CGRectMake (x, y, 29, 29); \t \t temp.userInteractionEnabled = YES; \t \t \t \t x + = 29; \t \t \t \t \t \t UITapGestureRecognizer의 탭 * = [UITapGestureRecognizer의 ALLOC] initWithTarget : 자기 조치 : @ 선택기 (imageTapped :)]; \t \t [temp addGestureRecognizer : tap]; \t \t [탭 해제]; 는하지만 얻을 : SIGABRT 오류 ... 인해 캐치되지 않는 예외 'NSInvalidArgumentException'응용 프로그램 종료, 이유는 : '- [DemoImageSlider2ViewController imageTapped :] : 인식 할 수없는 선택 예를 0x6c28a00로 전송'I가 핸들러 메소드 선언을 변경 – 1110
: - (void) imageTapped : (UIGestureRecognizer *) 발신자 { \t NSLog (@ "ITEM >>> % @", [arrayOfImages objectAtIndex : 8]); } 그리고 작동합니다, 감사합니다 :) – 1110