-1

我是 iPhone 新手,

我想在 ScrollView 中重复我的 PatternImage。

逻辑: 768bg.gif是我的图像,我添加了这个图像UIImageView,然后将 Imageview 添加到UIScrollView,但图像没有重复。

这是我的代码片段,

    CGRect scrollViewFrame = CGRectMake(0, 0, 1000, 600);
    UIScrollView *scrollVw = [[UIScrollView alloc] initWithFrame:scrollViewFrame];
    [self.view addSubview:scrollVw];
    [scrollVw release];

    UIImage *image1 = [UIImage imageNamed:@"768bg.gif"]; 
    self.imageView = [[UIImageView alloc] initWithImage:image1]; 
    [scrollVw addSubview:self.imageView]; 
    scrollVw.contentSize = CGSizeMake(image1.size.width+100, image1.size.height+100);

任何帮助都会得到帮助。

4

3 回答 3

2

您可以[UIColor colorWithPatternImage:]从记忆中使用 , 。

于 2012-08-08T06:09:30.543 回答
0

你可以参考这个链接....你要创造的是一个无限的UIScrollview权利?? http://mobiledevelopertips.com/user-interface/creating-circular-and-infinite-uiscrollviews.html

这里有一些示例代码供您理解....

for(int i=0; i < [Array count]; i++)
{       
    UIImageView *img = [[UIImageView alloc] init];
    [img setUserInteractionEnabled:YES];
    [img setTag:i];
    UITapGestureRecognizer *ges = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(setImage:)];
    ges.numberOfTapsRequired = 1;
    [img addGestureRecognizer:ges];
    img.bounds = CGRectMake(10, 10, 50, 50);
    img.frame = CGRectMake(0, yOffset, 50, 50);
    img.image = [UIImage imageNamed:[Array objectAtIndex:i]];
    [images insertObject:img atIndex:i];    
    ScrollView.layer.cornerRadius = 11;
    [ScrollView addSubview:[images objectAtIndex:i]];            
    yOffset += 50;
} 
ScrollView.contentSize = CGSizeMake(58,yOffset);
于 2012-08-08T06:11:12.397 回答
-2
  1. 使用图形编辑器从您的 gif 中提取所有图像(iphone 无法“播放”gif)

  2. 保存结果图像,如 name1.png、name2.png、name3.png(或您需要的任何扩展名)

  3. 将图像导入您的项目,然后说:

UIImageView *myImageView = [UIImageView alloc] bla-bla-create-the-imageview];

    [myImageView setFrame:CGRectMake(bla-bla-whatever)];
            myImageView.animationImages = [NSArray arrayWithObjects:    
                                    [UIImage imageNamed:@"name1.png"],
                                    [UIImage imageNamed:@"name2.png"],
                                    [UIImage imageNamed:@"name3.png"],
                                    [UIImage imageNamed:@"name4.png"],
                                    nil];
    myImageView.animationDuration = 2.0;//or whatever time interval
    myImageView.animationRepeatCount = 0;
    [myImageView startAnimating];
    //add the imageVew to scroll
于 2012-08-08T06:14:46.377 回答