2013-04-30 38 views
0
的UIImageView坐标辞退的UIScrollView

有一个UITableView有许多照片。在拍摄照片时,modalViewUIScrollView一起呈现,其中还嵌入有UIImageView。点击图片在这里展示(类似Facebook应用程序)。 现在,我可以使用touchesMovedCGRectMake垂直移动图像。 我想要实现的是,当我上下拖动图像,在达到一定的阈值时,ImageView的&滚动型应该会消失,我们应该回到的tableView。基于触摸上嵌入的UIScrollView

- (void) touchesMoved:(NSSet *)touches 
     withEvent:(UIEvent *)event { 
    UITouch * touch = [touches anyObject]; 
    CGPoint pos = [touch locationInView: [UIApplication sharedApplication].keyWindow]; 
    NSLog(@"%f", pos.y); 

if (pos.y>50&&pos.y<430){ 
    [UIView setAnimationDelay:0]; 

    [UIView animateWithDuration:0.4 

        animations:^{_photoImageView.frame=CGRectMake(0,pos.y-100,320,200);} 

        completion:^(BOOL finished){ }]; 
} 
} 

动作将控制返回给所述的tableView这里需要:

图片使用移动

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

UITouch * touch = [touches anyObject]; 
CGPoint pos = [touch locationInView: [UIApplication sharedApplication].keyWindow]; 

if (pos.y>50&&pos.y<430){ 
    [UIView setAnimationDelay:0]; 

    [UIView animateWithDuration:0.4 

        animations:^{_photoImageView.frame=CGRectMake(0,140,320,200);} 

        completion:^(BOOL finished){ }]; 
} 
else if(pos.y<50||pos.y>430) 
    //Code needed here !! 
    ; 
} 

此外,如果透明性可以在imageView背景(即,滚动型)来实现这样的该表视图是可见的某些阿尔法,这将不胜感激。

+0

要补充的UIView或UIViewController中 – 2013-04-30 07:57:11

+0

这是一个UIView。 – n00bProgrammer 2013-04-30 08:05:13

+0

[查看removeFromSuperView];你没有尝试这个视图是你的滚动视图 – 2013-04-30 08:07:43

回答

0

dismissModalViewControllerAnimated:中关闭(应使用较新的方法dismissViewControllerAnimated:completion:)。

(这是假设你带有presentModalViewController:animated:,只是添加视图屏幕是不是一个模态演示)。如果您没有真正呈现模式,那么只需使用removeFromSuperview即可。

当呈现视图模式方式下面的视图将显示被删除(它的预期不可见),所以如果你做的模态视图透明,你只会看到黑色的下方。如果你想让叠加视图透明,你应该把它设为子视图,设置不透明度(alpha)并使用bringSubviewToFront:

+0

如果是由我决定,我只能使用子视图。我对使用Modals有偏见。他们缺乏所需的灵活性。 – n00bProgrammer 2013-04-30 08:53:06