Does the iPhone display sliding photos / images (e.g. photo library and Facebook app)?

I started developing in iOS just a couple of days ago, so everything is very new to me! I need to show the “photo slider” in the application, as in the iPhone library or the Facebook application. After some research, I came to a dead end. My goal is to show a set of photos one by one, and the user slides a finger from right to left or vice versa :-)

Does anyone have an example or does anyone know?

Thanks to everyone.

+3
source share
4 answers

, Three20 , . , , , Three20 , URL-, .

, https://github.com/enormego/PhotoViewer. . , , http://developers.enormego.com/.

+7

. "scr" - scrollview.

NSMutableArray *imgs=[[NSMutableArray  alloc]init]; 
                         // arrayWithObjects:[UIImage @"abc1.jpg"],[UIImage @"abc2.jpg"],[UIImage @"abc3.jpg"], [UIImage@"abc4.jpg"],
//                [ UIImage @"abc5.jpg"],nil];

                      [imgs addObject:[UIImage imageNamed:@"abc1.jpg"]];
                      [imgs addObject:[UIImage imageNamed:@"abc2.jpg"]];
                       [imgs addObject:[UIImage imageNamed:@"abc3.jpg"]];
                        [imgs addObject:[UIImage imageNamed:@"abc4.jpg"]];
                         [imgs addObject:[UIImage imageNamed:@"abc5.jpg"]];
for(int i=0;i<imgs.count;i++)
{
    CGRect frame;
    frame.origin.x=self.scr.frame.size.width *i;
    frame.origin.y=0;
    frame.size=self.scr.frame.size;
    UIImageView *subimg=[[UIImageView alloc]initWithFrame:frame];
    subimg.image=[imgs objectAtIndex:i];
    [self.scr  addSubview:subimg];
    [subimg release];
    self.scr.contentSize=CGSizeMake(self.scr.frame.size.width*imgs.count, self.scr.frame.size.height);

}
+5

yhpets , ImageView ImageView ...

ViewController.h ...

@interface ViewController : UIViewController{
    NSMutableArray *imgs;
    IBOutlet UIScrollView *scr;
}
@property (strong, nonatomic) IBOutlet UIScrollView *scr;

And in your ViewController.m you need to listen to didRotateFromInterfaceOrientation and resize the ImageViews to fit the new screen. We need to set the screenWidth and screenHeight variables depending on whether we are a portrait or a landscape, and use them to resize each image and scroll.

@implementation ViewController
@synthesize scr;

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
        CGRect screenRect = [[UIScreen mainScreen] bounds];
        CGFloat screenWidth = screenRect.size.width;
        CGFloat screenHeight = screenRect.size.height;
    if ((self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)||(self.interfaceOrientation == UIInterfaceOrientationPortrait)){
//screenWidth and screenHeight are correctly assigned to the actual width and height
    }else{
        screenHeight = screenRect.size.width;
        screenWidth = screenRect.size.height;
        screenRect.size.width = screenWidth;
        screenRect.size.height = screenHeight;
    }
    NSLog(@"see it right now= (%f,%f)",screenWidth,screenHeight);
    self.scr.contentSize=CGSizeMake(screenWidth*imgs.count, screenHeight);
    for(int i=0;i<imgs.count;i++){
        UIImageView *targetIV = (UIImageView*)[self.view viewWithTag:(i+1)];
        CGRect frame;
        frame.origin.x=screenWidth *i;
        frame.origin.y=0;
        frame.size=CGSizeMake(screenWidth, screenHeight);
        targetIV.frame = frame;
    }
}///////////////////////////////////////////////////////////////////////////
- (void)viewDidLoad{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    imgs=[[NSMutableArray  alloc]init];
    [imgs addObject:[UIImage imageNamed:@"1001.png"]];
    [imgs addObject:[UIImage imageNamed:@"1002.png"]];
    [imgs addObject:[UIImage imageNamed:@"1003.png"]];
    [imgs addObject:[UIImage imageNamed:@"1004.png"]];
    for(int i=0;i<imgs.count;i++){
        CGRect frame;
        frame.origin.x=self.scr.frame.size.width *i;
        frame.origin.y=0;
        frame.size=self.scr.frame.size;
        UIImageView *subimg=[[UIImageView alloc]initWithFrame:frame];
        subimg.image=[imgs objectAtIndex:i];
        subimg.tag = (i+1);
        subimg.contentMode = UIViewContentModeScaleAspectFit;
        [self.scr  addSubview:subimg];
    }
    self.scr.contentSize=CGSizeMake(self.scr.frame.size.width*imgs.count, self.scr.frame.size.height);
}
+1
source

There is a “photo slider” in Three20, if you want to check it - https://github.com/facebook/three20/tree/master/samples/TTCatalog - just load the source and create a TTCatalog

0
source

Source: https://habr.com/ru/post/1787343/


All Articles