how to display image in image view with back and front options - iphone

im new to iphone now im working animals enclyclopidea. procedure is 6 image in 6 imageview when i click one image it comes full view and automaticaly go back in this we have to implement back and front options also.this is procedure.
so plz send me correct code for this animals enclyclopedia.
Thank u in advance.

you can invert your animations dictionary. If you have
[#"image1.png", #"image2.png", #"image3.png", nil];
then you programmatically set it to
[#"image3.png", #"image2.png", #"image1.png", nil];
and start animating again. And maybe you have to read the current image and set that as the first and calculate the others from this one.

Related

UIImagePicker add Caption

I can't test this code in the iphone simulator but I was wondering if this is the best way to add a caption to a photo someone has taken in the UIImagepickercontroller class.
- (void)imagePickerController:(UIImagePickerController *) Picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
_selectedImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];
UITextField *caption= [[UITextField alloc] initWithFrame:CGRectMake( 60,640,200,40)];
caption.borderStyle = UITextBorderStyleRoundedRect;
caption.font = [UIFont systemFontOfSize:15];
caption.placeholder = #"Type Caption";
[caption release];
}
This is the flow I would take
Let user select / take a picture
Once user hits ok show a prompt to let them enter text.
Sample Project 1
Sample Projects 2
Create a UIImageView and add their selected picture to it
Create a UILabel and add it on top of the UIImageView
Add their text to UILabel.
If you need to save the image with text on top of it then you need some sort of custom photo editor code or just take a screenshot and save it.
The code you posted does not make much sense for what you are trying to do, since it does not look like you are actually linking the caption to the image in any way. I also do not know why you are releasing the text field - unless you turned Automatic Reference Counting off, that code should return an error.
What I would do (and did, to an extent, in a project of mine) is the following:
(1) Create some sort of object, like UserImg, which has two properties of type UIImage and NSString respectively.
(2) In the above function, when an image is selected, create a new UserImg and set the UIImage property to the select image.
(3) Display an UIAlertView with a text box and an okay and cancel button. Use the text box to get the caption you want the user to save with the image.
(4) Set up a function to listen to the UIAlertView for okay and cancel button presses. If the user cancels, remove the new UserImg. If the user hits okay, copy the input text to the UserImg's NSString property.
(5) Profit? I am not sure of the context of the image taking, so you'll have to figure out how you want to display things yourself.
You can test this functionality on the simulator as well. You just need to set the code up so that it picks images from the device's image folder if no camera is present. I forget exactly how to do this and do not currently have my source code on me. I'll edit the answer later to include that if you cannot figure it out yourself in that time.
You will also have to add images to the simulator to choose from. To do that, exit out of any apps running on the simulator (hit the home button, like you would on an actual device) and drag an image over on top of it. When you do, in the top right corner, there should be an option to save the image to the device.
EDIT:
I noticed the comment you added about putting the caption below the image. To do that, I would create a UserImgView which consisted of a UIImageView and a UILabel. That way, when displaying the image using the custom view, you can display the UIImage in its ImageView and the caption right below it in the label.
Best way would be to create a NSDictionary
NSMutableDictionary *photoCaptionDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:_selected.image,#"image",caption.text,#"caption",nil];
Whenever you want to show the picture you just do
[photoCaptionDict objectForKey:#"image"];
and
[photoCaptionDict objectForKey:#"caption"];
shows the text.

Animating imageview takes time for first time

I am animating the ImageViews then the user taps a button. I have more than 40
images. The code I have used is
arr3 = [[NSArray alloc]initWithObjects:[UIImage imageNamed:#"Aperture_00000.png"],
[UIImage imageNamed:#"Aperture_00001.png"],
[UIImage imageNamed:#"Aperture_00002.png"],
...
[UIImage imageNamed:#"Aperture_00023.png"], nil];
imgv.animationImages = arr3;
imgv.animationDuration=2.0f;
imgv.animationRepeatCount =1;
The method to start the animation is:
-(void)animate {
[imgv startAnimating];
}
But it takes a lot of time when the user presses the button for the first time. What could be the solution for this?
The reason is following code:
arr3 = [[NSArray alloc]initWithObjects:[UIImage imageNamed:#"Aperture_00000"],[UIImage imageNamed:#"Aperture_00001"],[UIImage imageNamed:#"1.png",#"2.png",#"3png",#"4.png",#"5.png",#"6.png",#"7.png",#"8.png",#"9.png",#"10.png",#"11.png",#"12.png",#"13.png",#"14.png",#"15.png",];
What you can do is load this array somewhere else.
Note : This is a very memory consuming way of loading the images. Your app will definitely crash after you visit this class 2-3 times. Instead of this use some alternative. The easiest alternative I can suggest is load a image on UIImageView and change the image periodically. It'll give you animation effect.
I would suggest you rather doing it programmatically you should create animated gif image from the images. Here is online tool you can set speed and other parameters
http://picasion.com/
and use
https://github.com/arturogutierrez/Animated-GIF-iPhone
UIImageView category to display that gif image in that case you can save your CPU time.
Unhide the imageView when you want to play animation and hide when you want to stop.
I would suggest to give that at least a try.

iphone sdk how to switch an image and save it with a button press

I'm writing an application where I want an image to be displayed on the first page, but only on a small portion of the front page. What I've been trying to do is set up a button on a subview that will switch the image on the first view. This has had me stumped for hours.
Can anyone help?
Assuming that your view controller has a member variable named 'myImageView' that's hooked up to the actual UIImageView, then you can change a UIImageView's image, as follows (caveat: I haven't compiled this code so it may have minor errors):
// create some images
UIImage *imgPig = [[UIImage imageNamed:#"pig.png"] retain];
UIImage *imgCow = [[UIImage imageNamed:#"cow.png"] retain];
...
// sometime later, change the imageview to show a pig
[[self myImageView] image] = imgPig;
...
// sometime later, change the pig to a cow
[[self myImageView] image] = imgCow;
// finally release images
[imgPig release];
[imgCow release];
Or is the problem that you have about how to access the actual UIImageView? Or is it that you don't know how to detect the button press so that you can actually do something in response to the button being pressed?
Yes, that's right. I have three .h and .m files: appdelegate, the viewcontroller, and then a subview. What I'm trying to do is let the user change the image to a different image on the first page by using a button located on the subview. On the first view there's a label and a UIImageView (This imageview is the one i want to change). On the second view there's a UIButton. When this button is pressed, it should change the UIImageView on the first page.
The problem I've been having is letting the first page know that the button has been pressed, and changing the picture accordingly. Hope thats enough info for you to help. thanks!!
[edit to guy below me: sorry, I switched comptuers and couldnt edit the original post]

Displaying Map ONLY when the button is clicked in Xcode

I am developing an iPhone application using XCode and I am kinda stuck with the functionality described in the subject of this post.
I want the map(using MapKit) to only load and display after I click a button. So, what code should I have under that my "(IBAction) showMap" function?
Whatever I could find online talks about unhiding the map. I want to only load the map when a button is clicked rather than loading the map in the background and simply unhiding it the click of the the button. Thanks !
~Susanth
Your button click should open a new view, which contains Map. Since that view does not exist until it's loaded (viewDidLoad, viewWillAppear), you are not loading map or displaying it beforehands.
- (IBAction)showMap:(id)sender
{
self.mapController = [[MyMapViewController alloc]
initWithNibName:#"MyMapViewController" bundle:nil];
[self.mainView addSubview:mapController.view];
}
Many ways to do it... It takes time to load a map, so you might still consider loading it at background. Looks better (faster) for end-user.
use the below concept.
-(IBAction) showMap:(id)sender
{
// Add your Map to current view
[self.view addsubview:YOUR_MAPVIEW];
}
-(IBAction) hideMap:(id)sender
{
[YOURMAPVIEW removeFromSuperView];
}
Here you can create the MapView either from XIB file or by writing code.
Hope this helps.
Jim.

MPMoviePlayer Audio Album art

I am streaming an MP3 file using MPMoviePlayer, and I would like to have an image displayed instead of the default Quicktime logo in the background.
I found out a way to have an image overlay the player, but the problem with that, is you have to tap outside the image to get the player controls to appear. And when they do appear, they are underneath the image.
Does someone know how to do this?
Thanks,
John
backgroundColor is deprecated, and diving into private View structures is dangerous. This worked fine for me:
UIImageView *coverImageView = [[UIImageView alloc] initWithImage:coverImage];
coverImageView.contentMode = UIViewContentModeScaleAspectFit;
coverImageView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
coverImageView.frame = moviePlayerController.view.bounds;
[moviePlayerController.view addSubview:coverImageView];
Most every app on the iPhone is made of a hierarchy of views. You could go up to the top root node of the movie player and walk down the child views recursively and set the hidden value to YES until you find the right item, then insert your UIImageView below that item. That way, the controls stay on top and still respond to user inputs.
The risk you run is if Apple changes the MPMoviePlayer UI and shuffles the view hierarchy, but you'll probably have lots of advance notice and can patch your app to allow for the new layout.
There is a question as to whether this is kosher for appstore apps, but many current apps (especially camera/picture-taking ones) are doing it to get rid of standard window elements.
Use AVAudioPlayer and implement your own player UI.
it will work check this
MPMoviePlayerController *moviePlayerController=[[MPMoviePlayerController alloc] initWithContentURL:theURL];
moviePlayerController.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"Default.png"]];