如何将viewController推送到另一个带有scrollview图像的视图

时间:2011-10-14 06:21:04

标签: iphone uinavigationcontroller uiscrollview uiimageview

我有一个scrollview images,我想标记它们,然后推送到另一个视图。

一旦我在图片上选中,整个视图就会推到另一个视图。

从此视图到另一个视图

1

详情视图

2

很抱歉没有清楚地问这个问题。

我的滚动视图

-(void)pictureScrolling
{
//init scrollview in location on screen
scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 100, 320, 290)];   
scrollview.backgroundColor = [UIColor redColor];
//pass image filenames
NSMutableArray *fileNames = nearbyFrog.imageFiles; //[[[NSMutableArray alloc] init] autorelease];

//setup the array of uiimageviews
NSMutableArray *imgArray = [[NSMutableArray alloc] init];
UIImageView *imageView;

//loop through the array imgNames to add file names to imgArray
for (NSString *imageName in fileNames) {

    imageView = [[UIImageView alloc] init];
    imageView.image = [UIImage imageNamed:imageName];
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    [imgArray addObject:imageView];
    [imageView release];
}

CGSize pageSize = scrollview.frame.size; 
NSUInteger page = 0;

for (UIView *viewForScrollView in imgArray) {

    [scrollview addSubview:viewForScrollView];

    viewForScrollView.frame = CGRectMake(pageSize.width * page++ +10, 0, pageSize.width -20 , pageSize.height);

    // making use of the scrollView's frame size (pageSize) so we need to;
    // +10 to left offset of image pos (1/2 the gap)
    // -20 for UIImageView's width (to leave 10 gap at left and right)
}
//add scroll view to view
[self.view addSubview:scrollview];
scrollview.contentSize = CGSizeMake(pageSize.width * [imgArray count], pageSize.height);

//scrollview.contentSize = CGSizeMake(320 *viewcount + 20, 290 );
scrollview.showsHorizontalScrollIndicator =NO;
[scrollview setPagingEnabled:YES];
scrollview.delegate =self;

//paging function for scrollview
CGRect frame = [[UIScreen mainScreen] applicationFrame];
self.pageControl = [[[UIPageControl alloc] initWithFrame:CGRectMake(0, 100, 100, 50)] autorelease];
self.pageControl.center = CGPointMake(frame.size.width/2, frame.size.height-60);
self.pageControl.numberOfPages = [fileNames count];
[self.view addSubview:self.pageControl];    

//handle Touch Even
[pageControl addTarget:self action:@selector(changePage:) forControlEvents:UIControlEventValueChanged];
[imgArray release];

}

有人知道怎么做或者可以给我看一个教程吗?

谢谢

1 个答案:

答案 0 :(得分:1)

我认为这是实施它的最佳方式

  1. 创建自己的Custom UIImageView类。这需要存储一个附加属性,以帮助您识别要单击的图像。
  2. 为在UIImageView中引发单击事件而调用的该类创建委托
  3. 使用此自定义类在scrollview中添加图像。这个班级的代表会告诉你哪个图像被点击了。您可以使用它来推送新的视图控制器传递图像详细信息(如有必要)。
  4. 您可以在scrollviewSuite示例

    中的ThumbImageView类中找到一些示例代码

    http://developer.apple.com/library/ios/#samplecode/ScrollViewSuite/Introduction/Intro.html#//apple_ref/doc/uid/DTS40008904-Intro-DontLinkElementID_2