如何将ViewController推送到滚动视图中带有图像的另一个视图

发布于 2024-12-10 07:00:29 字数 2450 浏览 0 评论 0原文

我有一个 imagesscrollview,我想标记它们并将其推送到另一个视图。

一旦我点击图像,整个视图应该推送到另一个视图。

从此视图到另一个视图

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

}

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

谢谢

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.

From this View to another view

1

Detail view

2

Sorry for not asking the question clearly.

my scrollview

-(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?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

水中月 2024-12-17 07:00:29

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

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

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

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

I think this is the best way to implement it

  1. Create your own Custom UIImageView class. This is required to store an additional property which will help you identify which image for clicked.
  2. Create a delegate for that class which is called with the single tap event is raised in the UIImageView
  3. Add the Images inside the scrollview using this custom class. The delegate of this class will tell you which image was tapped. You can use this to push a new view controller passing the image details (if necessary).

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文