scrollRectToVisible在页面视图控制器中不起作用 - iPhone sdks

时间:2014-12-17 06:33:55

标签: ios iphone ios7 uiscrollview

我正在使用Xcode 6.1并开发iOS 8.0。

在我的应用程序中,我有一个UIPageViewController。我添加了UIScrollView。在UIScrollView我有4个按钮。当我点击按钮时,我使用此代码。

long btnValue = sender.tag;
float spaceing = 0;
if(btnValue == 1)
    spaceing = self.scrollView.frame.size.width/4*btnValue;
else
    spaceing = (self.scrollView.frame.size.width/2*btnValue) - self.scrollView.frame.size.width/4;
CGRect frame;
frame.origin.x =  spaceing;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
[self.scrollView scrollRectToVisible:frame animated:YES];
self.scrollView.pagingEnabled = NO;

这(scrollRectToVisible :)不起作用。任何人都可以帮助我吗?

感谢。

1 个答案:

答案 0 :(得分:0)

long btnValue = sender.tag;
float spaceing = 0;
if(btnValue == 1)
    spaceing = self.scrollView.frame.size.width/4*btnValue;
else
    spaceing = (self.scrollView.frame.size.width/2*btnValue) - self.scrollView.frame.size.width/4;
CGRect frame;
frame.origin.x =  spaceing;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
[self.scrollView scrollRectToVisible:frame animated:YES];
self.scrollView.pagingEnabled = NO;

//问题在这里

frame.size = self.scrollView.frame.size;   //scrollView.frame.size matters

frame.size = self.View.frame.size;

如果您是通过编码进行的,请将您的滚动视图添加到视图中

[self.view addSubview:yourScrollView];