iphone - 在 UIScrollView 中滚动到屏幕中心

标签 iphone objective-c ios uiscrollview

我有带标签的 UIScrollView。我正在获取触摸事件坐标。当用户点击屏幕时,我将点击坐标存储在变量中,然后我想 ScrollView (使用 [myScrollView setContentOffset] 之类的东西),这样点击点的 y 坐标将成为我 View 的中心,因此当您单击某些文本时,它会自动滚动到屏幕中央。我不确定如何计算这个...

非常感谢任何帮助!

最佳答案

UIScrollView *aScrollView;      
CGPoint touchPoint;
[aScrollView scrollRectToVisible:CGRectMake(touchPoint.x - roundf(aScrollView.frame.size.width/2.),
                                                  touchPoint.y - roundf(aScrollView.frame.size.height/2.), 
                                                  aScrollView.frame.size.width, 
                                                  aScrollView.frame.size.height)  
                                                  animated:YES];

应该可以。

关于iphone - 在 UIScrollView 中滚动到屏幕中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10293433/

相关文章:

iphone - 在 appdelegate 中呈现多个模态视图

ios - 使用 openurl 时,应用程序设置包未显示在设置应用程序中

iphone - 如何以编程方式创建选项卡栏

ios - Dropbox iOS Core SDK 不下载文件

ios - 基于 Objective C 中 map View 框架的坐标过滤数组

android - 如何保证Cordova App只能安装在手机上而不能安装在平板电脑上?

iphone - 具有 +0 保留计数的对象返回给调用者,其中期望 +1(拥有)保留计数

objective-c - 向手势识别器初始化选择器发送参数?

ios - UIAlertAction 处理程序在错误的时间调用?

ios - 获取 iOS 上导航栏的默认高度(或最大值)