简体   繁体   English

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

[英]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 . 现在,我可以使用touchesMovedCGRectMake垂直移动图像。 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.

相关问题 在UIScrollView中的UIImageView中检测触摸 - Detect touch in UIImageView in UIScrollView 将触摸手势发送到UIScrollView的UIImageView子视图 - Sending touch gestures to UIImageView subview of UIScrollView 如何在UIScrollview中检测UIImageView上的触摸? - How to detect touch on UIImageView inside UIScrollview? 在包含UITextView和UIImageView的UIScrollView中滚动后的触摸位置问题 - Problems with touch position after scrolling in UIScrollView that contains a UITextView and UIImageView 如何使用UIGestureRecognizers在UIScrollView内旋转UIImageView相对于触摸位置 - How to rotate a UIImageView inside a UIScrollView using UIGestureRecognizers, relative to the touch location 如何使UIActivityIndi​​cator显示在嵌入UIScrollView的UIImageView之上? - How to make UIActivityIndicator show on top of UIImageView embedded in UIScrollView? 在嵌入UIScrollView的UIImageView中加载20MB png - Loading a 20MB png in a UIImageView embedded in a UIScrollView 在UIScrollView背景中关闭UIKeyboardTypeDecimalPad - dismiss the UIKeyboardTypeDecimalPad in UIScrollView background uiscrollview内uiimageview上的UITapgesturerecognizer - UITapgesturerecognizer on uiimageview inside of uiscrollview 在UIScrollView的UIImageView中更改UIImage - changing UIImage in UIImageView in UIScrollView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM