代码改变世界

新浪博客中放大图片的做法

2013-09-27 17:11  甘超波  阅读(474)  评论(0编辑  收藏  举报

 

在自定义cell中子的UIImageview添加手势,单击手势触发下面的事件

 
UIImageview  _statuImage=[[UIImageView alloc] init];
        _statuImage.userInteractionEnabled=YES;
        [self.contentView addSubview:_statuImage];
        _statuImage.contentMode=UIViewContentModeScaleAspectFit;
        [_statuImage release];
        

            UITapGestureRecognizer *tap=[[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(openPic:)] autorelease];
            [_statuImage addGestureRecognizer:tap];

 

-(void)openPic:(UITapGestureRecognizer *)tap{
    
    
        [UIView beginAnimations:@"present" context:nil];
        [UIView setAnimationDuration:0.25];
                
        CGRect r = [[UIApplication sharedApplication] keyWindow].frame;
    
        alphaView = [[UIView alloc] initWithFrame:r];
        alphaView.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1];
        alphaView.alpha = 0.95;
       [[[UIApplication sharedApplication] keyWindow] addSubview:alphaView];
       [alphaView release];
    
        UITapGestureRecognizer *closeTap=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closePic)];
        [alphaView addGestureRecognizer:closeTap];
        [closeTap release];

        EGOImageView *img=[[EGOImageView alloc] initWithFrame:alphaView.bounds];
        [alphaView addSubview:img];
        [img release];
    
        [UIView commitAnimations];
    
       Status *frame=self.cellData.Mystaus;
        if (tap.view==_statuImage) {
            if (frame.originalImageUrl) {
                    [img setImageURL:[NSURL URLWithString:frame.originalImageUrl]];
            }

        }
        if (tap.view==_retweetStatusimg) {
            if (frame.retweetedStatus.originalImageUrl) {
                 [img setImageURL:[NSURL URLWithString:frame.retweetedStatus.originalImageUrl]];
            }

        }

}


-(void)closePic{
  
    [UIView beginAnimations:@"present" context:nil];
    [UIView setAnimationDuration:0.25];
    alphaView.frame = CGRectMake(0, 600, 320, 600);
    [UIView commitAnimations];
    [alphaView removeFromSuperview];
    
  
}