iPhone:带有多个 UIImageView 的 UIScrollview,具有放大/缩小效果
我的应用程序中有一个 UIscrollview,其中包含多个 UIimageview。我想应用捏放大/缩小功能。将 UIImageview 添加到 UIScrollView 的代码如下,
self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
[scViewObject setCanCancelContentTouches:NO];
scViewObject.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scViewObject.clipsToBounds = NO; // default is NO, we want to restrict drawing within our scrollview
scViewObject.scrollEnabled = YES;
scViewObject.alwaysBounceHorizontal=YES;
scViewObject.pagingEnabled = YES;
UIView *view = nil;
NSArray *subviews = [scViewObject subviews];
for (view in subviews)
{
[view removeFromSuperview];
}
int left=20;
numberOfViewController=[ListOfImages count];
//NSMutableArray *controllers = [[NSMutableArray alloc] init];
for (unsigned ii = 0; ii < numberOfViewController; ii++)
{
UIImageView *temp=[[UIImageView alloc] init];
temp.contentMode=UIViewContentModeScaleAspectFit;
temp.userInteractionEnabled = YES;
temp.multipleTouchEnabled = YES;
temp.clipsToBounds = YES;
temp.image=[ListOfImages objectAtIndex:ii];
temp.frame=CGRectMake(left, 0, 280, 365);
temp.tag=ii;
[scViewObject addSubview:temp];
left=left+320;
}
[scViewObject setContentSize:CGSizeMake((numberOfViewController * kScrollObjWidth), 365)];
scViewObject 是 UIscrollview。请建议我如何添加放大/缩小功能
I have a UIscrollview in my application which contains multiple UIimageview. I want to apply the pinch zoom in / out functionality.Code for adding UIImageview to UIScrollView is following
self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
[scViewObject setCanCancelContentTouches:NO];
scViewObject.indicatorStyle = UIScrollViewIndicatorStyleWhite;
scViewObject.clipsToBounds = NO; // default is NO, we want to restrict drawing within our scrollview
scViewObject.scrollEnabled = YES;
scViewObject.alwaysBounceHorizontal=YES;
scViewObject.pagingEnabled = YES;
UIView *view = nil;
NSArray *subviews = [scViewObject subviews];
for (view in subviews)
{
[view removeFromSuperview];
}
int left=20;
numberOfViewController=[ListOfImages count];
//NSMutableArray *controllers = [[NSMutableArray alloc] init];
for (unsigned ii = 0; ii < numberOfViewController; ii++)
{
UIImageView *temp=[[UIImageView alloc] init];
temp.contentMode=UIViewContentModeScaleAspectFit;
temp.userInteractionEnabled = YES;
temp.multipleTouchEnabled = YES;
temp.clipsToBounds = YES;
temp.image=[ListOfImages objectAtIndex:ii];
temp.frame=CGRectMake(left, 0, 280, 365);
temp.tag=ii;
[scViewObject addSubview:temp];
left=left+320;
}
[scViewObject setContentSize:CGSizeMake((numberOfViewController * kScrollObjWidth), 365)];
here scViewObject is UIscrollview. Please suggest that how can i add zoom in / out functionality
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要观看几个 ADC 视频:
WWDC 2010:使用滚动视图设计应用程序
WWDC 2011:高级滚动视图技术,
但基本上您需要在外部滚动视图的每个“页面”内实现缩放滚动视图并将每个图像添加到每个缩放滚动视图中。
另请参阅文档
和示例代码
There is a couple of ADC video that you'll want to watch:
WWDC 2010 : Designing Apps with Scroll views
WWDC 2011 : Advanced Scrollview Techniques
but basically you'll want to implement a zooming scrollview inside each "page" of the outer scroll view and add each image into each of these zooming scroll views.
Also see the documentation
And example code