【发布时间】:2019-08-31 20:22:51
【问题描述】:
我在 UIScrollView 内有 UIView,其中包含 4 个子视图。在点击子视图时,我想调整滚动视图的contentoffset 属性,使我点击的subview 与屏幕中心对齐。
我尝试了一些逻辑,但它无法正常工作。
-(void)onDragViewTapped:(UITapGestureRecognizer *)recognizer
{
CGFloat width = self.scrollVw.contentSize.width/2;
CGFloat vwWidth = recognizer.view.frame.size.width/2;
width = width - vwWidth - vwWidth/self.scrollVw.zoomScale -
width/self.scrollVw.zoomScale;
CGFloat height = self.scrollVw.contentSize.height/2;
CGFloat vwHeigh = recognizer.view.frame.size.height/2;
height = height- vwHeigh - vwHeigh/self.scrollVw.zoomScale -
height/self.scrollVw.zoomScale;
[self.scrollVw setContentOffset:CGPointMake(width, height)
animated:YES];
}
【问题讨论】:
标签: ios objective-c uiscrollview