[英]Dismiss UIScrollView based on touch coordinates on UIImageView embedded into the UIScrollView
UITableView
有很多照片。 輕拍照片時,將使用UIScrollView
呈現一個modalView
,該模型進一步嵌入了UIImageView
。 點擊的圖像顯示在此處(類似於Facebook應用)。 現在,我可以使用touchesMoved
和CGRectMake
垂直移動圖像。 我想要實現的是,當我垂直拖動圖像時,達到一定閾值時,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.