繁体   English   中英

根据嵌入到UIScrollView中的UIImageView上的触摸坐标关闭UIScrollView

[英]Dismiss UIScrollView based on touch coordinates on UIImageView embedded into the UIScrollView

UITableView有很多照片。 轻拍照片时,将使用UIScrollView呈现一个modalView ,该模型进一步嵌入了UIImageView 点击的图像显示在此处(类似于Facebook应用)。 现在,我可以使用touchesMovedCGRectMake垂直移动图像。 我想要实现的是,当我垂直拖动图像时,达到一定阈值时,ImageView和ScrollView应该消失,而我们应该回到tableView。

图片使用以下方式移动:

- (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背景(即,滚动型),使得该表视图是与某些阿尔法可见,这将是高度赞赏。

使用dismissModalViewControllerAnimated:关闭(应该使用更新的方法dismissViewControllerAnimated:completion:

(这是假设您呈现了presentModalViewController:animated:只是将视图添加到屏幕上不是模态呈现)。 如果您没有真正呈现模态,则只需使用removeFromSuperview

模态显示视图时,下面的视图将从显示中移除(预计它是不可见的),因此,如果将模态视图设为透明,则其下方只会显示黑色。 如果要使覆盖视图透明,则应使其成为子视图,设置不透明度( alpha )并使用bringSubviewToFront:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM