简体   繁体   English

如何将scrollview中的图像推送到另一个视图

[英]how to pushViewController to another view with images in a scrollview

I have a scrollview of images , I will like to tab them and will pushed to another view. 我有一个images scrollview ,我想将它们制表,并将其推到另一个视图。

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 谢谢

I think this is the best way to implement it 我认为这是实现它的最好方法

  1. Create your own Custom UIImageView class. 创建您自己的Custom UIImageView类。 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 为该类创建一个委托,在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 您可以在scrollviewSuite示例的ThumbImageView类中找到一些示例代码。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM