[英]Dismiss UIScrollView based on touch coordinates on UIImageView embedded into the UIScrollView
There is a UITableView
with many photos. UITableView
有很多照片。 As a photo is tapped, a modalView
is presented with UIScrollView
, which further has an UIImageView
embedded into it. 轻拍照片时,将使用UIScrollView
呈现一个modalView
,该模型进一步嵌入了UIImageView
。 The tapped image is presented here (similar to the Facebook app). 点击的图像显示在此处(类似于Facebook应用)。 Now, i can move the image vertically using touchesMoved
and CGRectMake
. 现在,我可以使用touchesMoved
和CGRectMake
垂直移动图像。 What i want to achieve is that when i drag the image vertically, on reaching a certain threshold, the ImageView & ScrollView should disappear and we should be back to the tableView. 我想要实现的是,当我垂直拖动图像时,达到一定阈值时,ImageView和ScrollView应该消失,而我们应该回到tableView。
Image moved using: 图片使用以下方式移动:
- (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){ }];
}
}
The action to return control to the tableView is needed here: 这里需要将控制权返回给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 !!
;
}
Further, if transparency can be achieved on the imageView
background (ie Scrollview) such that the table view is visible with certain Alpha, that would be highly appreciated. 此外,如果透明性可以在能够实现imageView
背景(即,滚动型),使得该表视图是与某些阿尔法可见,这将是高度赞赏。
Dismiss with dismissModalViewControllerAnimated:
(should use the newer method dismissViewControllerAnimated:completion:
). 使用dismissModalViewControllerAnimated:
关闭(应该使用更新的方法dismissViewControllerAnimated:completion:
。
(This was assuming you presented with presentModalViewController:animated:
, just adding a view to the screen is not a modal presentation). (这是假设您呈现了presentModalViewController:animated:
只是将视图添加到屏幕上不是模态呈现)。 If you didn't really present a modal then just use removeFromSuperview
. 如果您没有真正呈现模态,则只需使用removeFromSuperview
。
When presenting a view modally the view below will be removed from display (it's expected not to be visible), so if you make the modal view transparent you will just see black below it. 模态显示视图时,下面的视图将从显示中移除(预计它是不可见的),因此,如果将模态视图设为透明,则其下方只会显示黑色。 If you want to make the overlay view transparent you should just make it a subview, set the opacity ( alpha
) and use bringSubviewToFront:
. 如果要使覆盖视图透明,则应使其成为子视图,设置不透明度( alpha
)并使用bringSubviewToFront:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.