iphone - change the color of a selected portion of a view with LongGestureRecognizer in ios -


i having app in using uilongpressgesturerecognizer.

what want that, when user touches portion of view 3 seconds, portion of view should change color.

if user touches part of view, portion should change color.

i trying below code.

uilongpressgesturerecognizer *lpgr = [[uilongpressgesturerecognizer alloc]                                           initwithtarget:self action:@selector(handlelongpress:)];     lpgr.minimumpressduration = 2.0; //seconds     lpgr.delegate = self;     [self.view addgesturerecognizer:lpgr];  -(void)handlelongpress:(uilongpressgesturerecognizer *)gesturerecognizer {   cgrect frame = cgrectmake(0.0, 0, 200, 200);     uiview * backgroundview;      backgroundview = [[uiview alloc] initwithframe:frame];      [backgroundview setbackgroundcolor:[[uicolor alloc] initwithred:204./255 green:213./255 blue:216./255 alpha:0.5]];      [self.view addsubview:backgroundview]; } 

with code can change color of frame set.

but how change color of part of screen user touches?

is possible so?

if yes, how can this?

please me.

edited

i got location co-ordinates below codes how find "touch area" means height , width of touched portion?

please tell me if knows it.

is possible?

please me.

thanks in advance.

try this, didn't test it. should work. understood need highlight parts before second press event called...

-(void)handlelongpress:(uilongpressgesturerecognizer *)gesturerecognizer {     //check if old highlight exists , remove if true uiview *oldview = [self.view viewwithtag:999]; if(oldview != nil)     [oldview removefromsuperview];  cgpoint location = [gesturerecognizer locationinview:self.view];  cgrect frame = cgrectmake(location.x-100, location.y-100, 200, 200); uiview * backgroundview; backgroundview.tag = 999; //mark view highlight  backgroundview = [[uiview alloc] initwithframe:frame]; [backgroundview setbackgroundcolor:[[uicolor alloc] initwithred:204./255 green:213./255 blue:216./255 alpha:0.5]]; [self.view addsubview:backgroundview]; } 

// case

-(void)handlelongpress:(uilongpressgesturerecognizer *)gesturerecognizer {  uiview *oldview = [self.view viewwithtag:999]; cgpoint location = [gesturerecognizer locationinview:self.view];  (uiview *subview in self.view.subviews) {    if(cgrectcontainspoint([subview.frame], location))    {             cgrect frame = subview.frame;             uiview * backgroundview;             backgroundview.tag = 999; //mark view highlight              backgroundview = [[uiview alloc] initwithframe:frame];             [backgroundview setbackgroundcolor:[[uicolor alloc] initwithred:204./255 green:213./255 blue:216./255 alpha:0.5]];             [self.view addsubview:backgroundview];    } } } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -