如何在滚动视图中将ViewViewController推送到具有图像的另一个视图 [英] how to pushViewController to another view with images in a scrollview

查看:54
本文介绍了如何在滚动视图中将ViewViewController推送到具有图像的另一个视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的scrollviewimages,我想将它们制表并推送到另一个视图.

I have a scrollview of images, I will like to tab them and will pushed to another view.

一旦我在图片上设置了标签,整个视图便应推送到另一个视图.

once i tab on the image, the whole view should push to another view.

从该视图到另一个视图

详细信息视图

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

Sorry for not asking the question clearly.

我的滚动视图

-(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];

}

任何人都知道该怎么做或可以给我看一个教程吗?

anybody knows how to do it or can show me a tutorial?

谢谢

推荐答案

我认为这是实现它的最佳方法

I think this is the best way to implement it

  1. 创建您自己的Custom UIImageView类.这是存储附加属性所必需的,它将帮助您确定要点击的图像.
  2. 为该类创建一个委托,该委托在UIImageView中引发单击事件时被调用
  3. 使用此自定义类将图像添加到滚动视图内.此类的代表将告诉您点击了哪个图像.您可以使用它来推动新的视图控制器,以传递图像详细信息(如有必要).

您可以在scrollviewSuite示例的ThumbImageView类中找到一些示例代码

You can find some sample code in the ThumbImageView class in the scrollviewSuite sample

查看全文

相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆