1
Setting:
Load some images into one NSArray
and show them in a UIImageView
as it is done in the photo gallery. But without the edit options. Just view and switch to the side using Swipe.
I made a code manually, but I did not get the desired final result.
Code I made:
#import "ViewController.h"
@interface ViewController (){
// Array para salvar imagens
NSArray* imagens;
//Imagens
UIImage* img1, *img2, *img3;
// ScrollView que fará a mudança
IBOutlet UIScrollView *scrollView;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// Pegando as imagens
img1 = [UIImage imageNamed:@"acai11.jpg"];
img2 = [UIImage imageNamed:@"gloria4.jpg"];
img3 = [UIImage imageNamed:@"gloria5.jpg"];
// Alocando cada uma em uma posição no array
imagens = [[NSArray alloc] initWithObjects:img1,img2,img3, nil];
// Pegando as dimensões de scrollView e passando para tamanhoPagina
CGSize tamanhoPagina = scrollView.frame.size;
NSUInteger pagina = 0;
// Iniciando e posicionando uma imagem dentro do ScrollView
for (int i = 0; i < [imagens count]; i++)
{
// Criando um UIImgageView
UIImageView *imgView = [[UIImageView alloc] init];
// Passando o tamanho do scrollView para imagView, para que a imagem tenha o mesmo tamanho que o ScrollView
imgView.frame = CGRectMake(320*i, 0, 300, scrollView.frame.size.height);
imgView.image = [imagens objectAtIndex:i];
[scrollView addSubview:imgView];
imgView.frame = CGRectMake(tamanhoPagina.width * pagina ++ + 10, 0, tamanhoPagina.width - 20, tamanhoPagina.height);
}
scrollView.contentSize = CGSizeMake( scrollView.frame.size.width * imagens.count, scrollView.frame.size.height);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
Below I will list the photos of the final result I wish:
I believe that there are native options for this task, and that it is not complex or difficult to implement.
Any question with the question just comment that I can add more information or provide details of the question.
Thanks @Gian, I will check and bring a return!!
– Tiago Amaral
Good @Gian, I took a look, but they explain far beyond what I want. In the app I’m doing I don’t need to show mosaic of the other images, just show a Uiviewcontroller and perform the exchange of them, animated way, using Gesture.
– Tiago Amaral
@Tiagoamaral, I presented these options to you to have a basis of how you could do it, not that it was necessary to implement the entire gallery. It was more presenting you the "basic" principles to help you do what you need. The means to get where you want are various. I leave you a more specific link dedicated to what you wish to do:http://code.tutsplus.com/tutorials/build-a-simple-photo-gallery-with-uigesturerecognizer-mobile-8480
– Gian
thanks again for bringing these links, which are really helping, and I’m seeing here other tutorials explaining how to implement something as I want. But I’ll keep the question open just yet, if anyone else can do/find a code snap showing the implementation, or at least one that shows a more accurate note. But anyway, I appreciate the effort and clarification.
– Tiago Amaral
Well I managed to make a code that does almost what I need, I just need to make a get center to improve the transition.
– Tiago Amaral
I’ll put the new code up there. @Gian, take a look if you understand a little Objective-C. Thanks
– Tiago Amaral
This
getCenter
would be the center of the device screen to center the image?– Gian
yes! You would need to do that effect of tagging the image to the middle when the next one had already appeared... do you have iPhone? you know what I’m talking about?
– Tiago Amaral
I don’t have iPhone, but I work with iOS, I believe I understand more or less what you want to do. For this just do some calculations that is easy to get.
– Gian
Yes I’m seeing and testing some measurements here, but it’s missing something... because from what I saw it slightly alters the speed of the image passage...
– Tiago Amaral
The center of the screen for example you can only divide by 2 the width and the height. If you want to center can: origemX = (widthTela / 2) - (widthImage / 2) then you adjust the height
– Gian
It has a kind of easy-in and easy-out animation in the transition
– Gian
I think the easy-in and the easy-out is connected to the zoom of images.
– Tiago Amaral
I managed to do it, and it’s very simple!! Tomorrow I will post the answer, because I can only answer my own question after 2 days. And it was a lot easier than I thought!!!
– Tiago Amaral