Image Swiping In Objective-C - iphone

I'm just a beginner to iphone development.
Recently i'm doing a project in which images need to be swiped. Could any one help me with it?
The images are stored in a server whose link is given.
I'm need it badly. So please help me
thank you

There are two ways.
You could either look at using a Paging Scroll View
Or, You could look at getting a series of UIImageViews with the correct images in each and then setting up a UISwipeGestureRecogniser for both directions. On the swipe's event handler you can adjust the x and y positions of the imageViews.
This is basic stuff. You should read some of the How-to's on Apple's developer website to help you with the base knowledge.
Edit:
Regarding the Internet images, the code can be adapted into the paging scroll view example:
NSString *path = #"http://merrimusings.mu.nu/archives/images/groundhog2.jpg";
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data cache:NO];
Load the strings from an NSMutableArray instead and you're good to go!

Use Three20 photo Album. Your problem will be solved.

Related

Append url to image path NSString?

I'm developing an iOS application consisting of a static sqlite database, series of tableviews and tab based detail view where the first view loaded in the detailview is a swipable imageView which loads a series of images.
I've got it working with this code where it looks for the image locally but I'd like to have it load the image from a URL or display a default image if no internet connection is available.
The images are named in the database as (for the example) image.jpg and I'd like all of them to load from the same URL directory (for the example) http://www.someurl.com/images/
Thank you
- (UIImage *) imageAtIndex:(NSUInteger)index {
Image *currentImage = (Image *) [self.images objectAtIndex:index];
NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:#"%#",[[currentImage filename] stringByDeletingPathExtension]] ofType:#"jpg"];
return [UIImage imageWithContentsOfFile:path];
}
The process for this is really very simple:
Try to download your image data using NSURLConnection
If successful, create a UIImage from the data
If either of the above fails, switch over to your placeholder/built-in image
Display the resulting image
I advise you have some sort of placeholder while the image is downloading, since that can take quite a while.
Don't bother with reachability; it's not 100% reliable, whereas actually trying the download is.
Avoid doing this on a background thread or queue. NSURLConnection is asynchronous out of the box to make this easier for you. There are a ton of third-party frameworks that try to simplify working with connections if you wish, though.
NSString *urlStr = [#"http://www.someurl.com/images/" stringByAppendingString:[currentImage filename]];
NSURL *url = [NSURL URLWithString:urlStr];
NSData *imageData = [NSData dataWithContentsOfURL:url];
UIImage *image = [[UIImage alloc] initWithData:data];
Or something like that...
If the image is large or the internet connection is slow, the NSData initialization might take some time. Consider getting the images data in a background thread, or use some existing framework for that like SDWebImage

ScrollView with over 150 images crashes

I've an application which is a scrollView filled with over 150 images .. I've followed this tutorial to create it .. the application is over 550MBs and it has about 500 (150 for iPhone 5 & 150 for Retina & 150 for non-retina & buttons) photos .. The application runs very well on the simulator with no problems but on a real device when I open the application it keeps loading then a crash
so can anyone help me with this, please?
Thanks in advance.
Try to load only those images needed for displaying. ie while scrolling those images that are hidden should be taken off from the scrollview. Maybe you can make a design similar to the working of reusable UITableViewCell. ie a custom implementation for showing only the needed images and reusing them while scrolling.
There is another way, not a straight forward one, you can use a UITableView and add images to each cell and then rotate the tableview so that it will look like an horizontal scroll.
The advantage of doing this method is that the UITableView will handle all the reusability issue and we dont need to worry about. But I am not sure whether its the right way to do this.
Btw.. I have uploaded an app with the UITableView rotated horizontal scroll view to the appstore without getting rejected ;)
It is not an good way to do that ,u can upload your photo on server side and when open the app. loading the image from server.
id path = #"http://upload.wikimedia.org/wikipedia/commons/c/c7/Sholay-Main_Male_Cast.jpg";
NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];
imageView.image = img;
LooK at this answer

adding a complex animation without using UIImage

i want to create a childrens book like this one:
http://www.youtube.com/watch?v=Sc1APRfP2o8
and i wanted to know, How do i create the animations? I have searched and all i can find are creating animations via putting together UIImages and then playing them. But i sure hope i do not have to do this with my whole book. I was wondering if there is another program i could use to create the animation in and then import it into Xcode and then just call it to play. Is this possible? Thanks a bunch!
Check out Cocoas2D.
I didn't watch the video but if you want to create an animation easily aybe you can try gif
NSData *gif = [NSData dataWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:#"filename" ofType:#"gif"]];
UIWebView *view = [[UIWebView alloc] initWithFrame:frame];
[view loadData:gif MIMEType:#"image/gif" textEncodingName:nil baseURL:nil];
this might work

Loading server image using initWithData not working

I am using following code to display image from server in UIImageView.
NSURL *url = [NSURL URLWithString:#"http://www.gettyicons.com/free-icons/125/miscellaneous/png/256/apple_256.png"];
NSData *imageData =[[NSData alloc] initWithContentsOfURL:url];
imgLargePicture.image = [[UIImage alloc] initWithData:imageData];
I can see the picture in Saffari but the image is not rendered in the iPhone application. I searched a lot on net and even in stackoverflow, everywhere this same code is given to display image from server. But in my case somehow its not working.
Can anyone please help me with this?
I use the same code of you and i get the image, so please check the NSData and make sure that imageView IBOutlet should be properly connected. Same code is running fine at my side i have check in xcode.
Just tried that code in my app and it worked. You are not adding that "imgLargePicture" (I assume it's a UIImageView) as your UIViewController's view subview or not giving it a proper frame.
Try this in your -viewDidLoad: and see if it works
UIImageView *imgLargePicture = [[UIImageView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:imgLargePicture];
NSURL *url = [NSURL URLWithString:#"http://www.gettyicons.com/free-icons/125/miscellaneous/png/256/apple_256.png"];
NSData *imageData =[[NSData alloc] initWithContentsOfURL:url];
imgLargePicture.image = [[UIImage alloc] initWithData:imageData];
This was happening because of proxy server setup in the organization. It required me to provide user name & password to go through proxy. So this is fixed by implementing AuthenticationChallenge method where I passed the credentials.

UIImage View + Pinch/Zoom feature when image is downloaded from web

I have a UIImageView, which pics up different images from the web, they are all different res. I have them to display as Aspect fit so that the whole picture displays even if it means leaving empty space on top or sides.
What i want to have the feature of doing is, once its displayed, to zoom in and out using the pinch or any other way.
NSURL* iURL = [NSURL URLWithString:tURL];
NSData* iData = [NSData dataWithContentsOfURL:iURL];
UIImage* iImage;
iImage = [UIImage imageWithData:iData];
FullScreenImage.image = iImage;
All this code is being executed on another thread, then it returns to the main thread and is displayed on a view using
[navigationController pushViewController:vFullscreen animated:YES];
Thanks for the help
You will need to use a UIScrollView as UIImageView does not offer any built-in zooming. See the Apple example entitled: ScrollViewSuite