iOS - UIScrollView 不工作(它根本不滚动 - 图像保持固

iOS - UIScrollView is not working (it doesn#39;t scroll at all - the image stays fixed)(iOS - UIScrollView 不工作(它根本不滚动 - 图像保持固定))
本文介绍了iOS - UIScrollView 不工作(它根本不滚动 - 图像保持固定)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在图像视图中显示图像(宽度:320 像素,高度:1250 像素).

I would like to display an image (width: 320 pixels, height: 1250 pixels) in an image view.

当我编译应用程序时,我根本没有滚动.视图保持不变.

When I compile the application I get no scrolling at all. The view stays fixed.

我做了什么:

  1. 通过 Interface Builder 在我的视图中添加了一个 UIScrollView.
  2. 通过 Interface Builder 向我的视图添加了一个 UIImageView.
  3. 验证 UIImageView 在 Interface Builder 中位于 UIScrollView 之下.
  4. 使用 ViewDidLoad 设置 UIScrollView 的大小.
  1. Added an UIScrollView via Interface Builder to my view.
  2. Added an UIImageView via Interface Builder to my view.
  3. Verified that UIImageView is below UIScrollView in Interface Builder.
  4. Set the size of the UIScrollView with ViewDidLoad.

我该怎么做?

代码:

- (void)viewDidLoad
{
    [super viewDidLoad];
    scrollView.contentSize = CGSizeMake(320, 1250);
}

截图:

ImageView:

ScrollView:

推荐答案

我刚刚做了同样的任务..试试这个.....

I just have done the same task.. Try this one.....

scrollView.delegate = self;
scrollView.scrollEnabled = YES;

int scrollWidth = 120;
scrollView.contentSize = CGSizeMake(scrollWidth,80);     


int xOffset = 0;
imageView.image = [UIImage imageNamed:[imagesName objectAtIndex:0]];

for(int index=0; index < [imagesName count]; index++)
{       
    UIImageView *img = [[UIImageView alloc] init];
    img.bounds = CGRectMake(10, 10, 50, 50);
    img.frame = CGRectMake(5+xOffset, 0, 50, 50);
    NSLog(@"image: %@",[imagesName objectAtIndex:index]);
    img.image = [UIImage imageNamed:[imagesName objectAtIndex:index]];
    [images insertObject:img atIndex:index];         
    scrollView.contentSize = CGSizeMake(scrollWidth+xOffset,110); 
    [scrollView addSubview:[images objectAtIndex:index]];

    xOffset += 70;
}

也设置这个....

imagesName = [[NSArray alloc]initWithObjects:@"image1.jpg",@"image2.jpg",@"image3.jpg",@"image4.jpg",@"image5.jpg",@"image6.png",@"image7.png",@"image9.png",nil];
    images = [[NSMutableArray alloc]init];

这篇关于iOS - UIScrollView 不工作(它根本不滚动 - 图像保持固定)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How to send an image with custom keyboard iOS(如何使用自定义键盘IO发送映像)
iOS convert audio sample rate from 16 kHz to 8 kHz(IOS将音频采样率从16 kHz转换为8 kHz)
Enforcing an audio sampling rate in iOS(在iOS中强制音频采样率)
How to fix ‘TIC SSL Trust Error’ in iOS?(如何修复 iOS 中的“TIC SSL 信任错误?)
quot;Server certificate untrustedquot; error in iPhone application(“服务器证书不受信任iPhone应用程序中的错误)