【发布时间】:2011-12-01 10:50:26
【问题描述】:
我有一个scrollview,我正在使用imageview。我的水平 scrollview 大小为 320 宽和 40 像素高。
我在scrollview 上有很多图片。
我希望当图像位于scrollview 的中心时,图像的大小应该按比例增加 40%。
【问题讨论】:
标签: iphone objective-c uiscrollview uiimageview
我有一个scrollview,我正在使用imageview。我的水平 scrollview 大小为 320 宽和 40 像素高。
我在scrollview 上有很多图片。
我希望当图像位于scrollview 的中心时,图像的大小应该按比例增加 40%。
【问题讨论】:
标签: iphone objective-c uiscrollview uiimageview
您的图像视图最好考虑在滚动视图中而不是在它上面。因此,您可以使滚动视图与图像的放大尺寸一样高。你会想象将图像垂直居中放置。您的滚动视图将位于作为滚动视图委托的视图控制器中。然后,视图控制器可以检查滚动视图的偏移量,以确定哪个图像在中心,并确保它被放大,并确保所有其他图像都被缩小。
你的下一个问题是looping the scrollview
【讨论】:
在viewDidLoad中实现定时器:
NSTimer *t;
[t scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(timerFired1:) userInfo:nil repeats:YES];
为计时器创建回调:
- (void)timerFired1:(NSTimer *)timer {
if (clubScrollView.contentOffset.y + clubScrollView.frame.size.heigth/2 == yourImage.frame.center)
[UIView animateWithDuration:1
animations:^{
[YourImage setFrame:CGRectMake(x, y, width, height)]; //set any frame
}];
}
使viewWillDisappear中的计时器失效:
[t invalidate];
【讨论】:
UIView 作为您的clubScrollView 的子视图,并将您的图像添加为此UIView 的子视图。另外,在你的for cicle 的每一步,使这个UIView 的框架更大,并设置clubScrollView 的contentSize 属性更大。然后,使用此代码修改您的问题