hello need ios app. how can background color of image (that insert in uiimageview) tap. create tap gesture recognizer not know how read background color tap.
try part of code found on stackoverflow:
in viewdidload:
code:
uitapgesturerecognizer * taprecognizer = [[uitapgesturerecognizer alloc] initwithtarget:self action:@selector(tapgesture:)]; [self.view addgesturerecognizer:taprecognizer];
and define:
code:
- (void)tapgesture:(uitapgesturerecognizer *)recognizer { cgpoint point1 = [recognizer locationinview:recognizer.view]; uigraphicsbeginimagecontext(recognizer.view.bounds.size); cgcontextref context = uigraphicsgetcurrentcontext(); [recognizer.view.layer renderincontext:context]; int bpr = (int)cgbitmapcontextgetbytesperrow(context); unsigned char data = cgbitmapcontextgetdata(context); if (data != null) { int offset = bpr*round(point1.y) + 4*round(point1.x); int blue = data[offset+0]; int green = data[offset+1]; int red = data[offset+2]; int alpha = data[offset+3]; nslog(@"%d %d %d %d", alpha, red, green, blue); if (alpha == 0) { // here tap out of text } else { // here tap right text } } uigraphicsendimagecontext(); }
error on cgbitmapcontextgetdata
code:
cannot initialize variable of type 'unsigned char *' r value of type 'void *'
and not know how change it.
Forums iPhone, iPad, and iPod Touch iOS Programming
- iPhone
- Mac OS & System Software
- iPad
- Apple Watch
- Notebooks
- iTunes
- Apple ID
- iCloud
- Desktop Computers
- Apple Music
- Professional Applications
- iPod
- iWork
- Apple TV
- iLife
- Wireless
Comments
Post a Comment