开发者

how to highlight the image on touch event in iphone

hi friend i created this method for image select it working proper but i am facing problem on image when i touch the image i cant see image click or not i want highlight the image when i touch on it how can i do this

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint location= [touch locationInView:self.view];
    if(CGRectContainsPoint(firstImage.frame, location)) 
    {
        //  flag like
        select=1;        
    }
    else if(CGRectContainsPoint(secImage.frame, location))
    {
        select=2;        
    }
    [mComment resignFirstResponder];

}

- (void)touchesEn开发者_如何转开发ded:(NSSet *)touches withEvent:(UIEvent *)event { 

    UITouch  *touch = [[event allTouches] anyObject]; 
    CGPoint location = [touch locationInView:self.view];

    if(CGRectContainsPoint(firstImage.frame, location)) {   
        if(select==1) {

            var=1;
        }}
    else if(CGRectContainsPoint(secImage.frame, location))  { 

        if(select==2) {
            vars=1;
        }}
    select=0; 
}


One thing you can do for highlight the image when you touch on it. When you touch on image you should change the alpha of selected image in touch began method and reset the image alpha in touch ended method. So its look like button.

For Ex.

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch *touch = [[event allTouches] anyObject];
    CGPoint location= [touch locationInView:self.view];
    if(CGRectContainsPoint(firstImage.frame, location)) 
    {
        //  flag like
        select=1;        
        firstImage.alpha = 0.5;
    }
    else if(CGRectContainsPoint(secImage.frame, location))
    {
        select=2;        
        secImage.alpha = 0.5;
    }
    [mComment resignFirstResponder];

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 

    UITouch  *touch = [[event allTouches] anyObject]; 
    CGPoint location = [touch locationInView:self.view];

    if(CGRectContainsPoint(firstImage.frame, location)) {   
        if(select==1) {
            firstImage.alpha = 1.0;
            var=1;
        }}
    else if(CGRectContainsPoint(secImage.frame, location))  { 

        if(select==2) {
            secImage.alpha = 1.0;
            vars=1;
        }}
    select=0; 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜