简体   繁体   English

如何在Iphone中点击UIButton设置UiScrollView Frame?

[英]How to set UiScrollView Frame on click of UIButton in Iphone?

I have UIScrollView on which I am using 2 UIButtons. 我有UIScrollView我正在使用2 UIButtons。 UIScrollView initial frame is (0,0,768,1024). UIScrollView初始帧是(0,0,768,1024)。 I want when I click on first button the UIScrollView y-cordinate position will be 500, means it will scrolldown 500 positions below to its actual position. 我想当我点击第一个按钮时,UIScrollView y-cordinate位置将为500,意味着它将向下滚动500个位置到其实际位置。

And when I click second Button which Will show on UIScrollView, Position Y-cordinate of UIScrollView y=535, then UIScrollView Move up to Position y= 0 again. 当我点击将在UIScrollView上显示的第二个按钮,UIScrollView的位置Y坐标y = 535,然后UIScrollView再次向上移动到位置y = 0。

First button click UIScrollView y = 500 Second button click UIScrollView y = 0 第一个按钮单击UIScrollView y = 500第二个按钮单击UIScrollView y = 0

Any hints from experts would be very welcome. 任何来自专家的提示都将非常受欢迎。

Maybe you do not want to change the frame of the scroll view (this would just displace the whole view), but the contentOffset . 也许你不想改变滚动视图的frame (这只会取代整个视图),而是contentOffset This can be animated, too. 这也可以动画。

CGPoint offset = scrollView.contentOffset;
offset.y += 500;
[scrollView setContentOffset:offset animated:YES];

This may solve ur pbm 这可以解决你的pbm

-(IBAction) clickfirstbutton 
{
   [scrollview setContentOffset:CGPointMake(0, 500)) animated:TRUE];
}

-(IBAction) clicksecondbutton
{
   [scrollview setContentOffset:CGPointMake(0, 0) animated:TRUE];
}

If u don't want animations use 如果你不想动画使用

[scrollview setContentOffset:CGPointMake(0, 0) animated:FALSE];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM