Display an image on screen after button is pressed in Cocoa - iphone

I was wondering what I should use to display an image on screen every time the user presses a button. I am using Objective-C/CocoaTouch on the iPod Touch. I would like to pull these images from an array I have set up and place them on the screen when the button is triggered. I feel dumb asking but any one that can point me in the right direction would be great. I think I could figure out the rest from there.
Thanks.

I'm sure there are many ways of doing this, but one way would be to define a UIImageView on the screen, and make it hidden. When the user presses the button, you can set the source of the UIImageView to the image from your array, and set the hidden property to NO.

I think it's as simple as something like this:
[myImageView setImage:[imageArray objectAtIndex:theIndex]];
In your button's action method. You can set theIndex before or afterwards to get a different image from your array every time the action method gets called.

Related

How can I highlight the BarButton in navigation bar without tapping it?

Typically, the UIBarButtonItem will be highlighted when we tap it.
However, I intend to show the users that the action is automatically done for them when the view is loaded after 4 sec.
So I want to highlight the Button without tapping it.
How can I achieve that?
For a UIVIew object such as a UIButton, you can either use the following code Glow category on UIView that adds support for making views glow or use this example.
If you are using the first one, you can just call startGlowing and stopGlowing. When you call startGlowing, the view will start to pulse with a soft light, this effect is removed when stopGlowing is called. Check this.
For UIBarButtonItem, you might have to use the solution provided here.

How to make the MapView a button (iPhone/iPad)?

I currently have a map view in my app that is locked so that the user can't interact with it (i.e. scroll, zoom etc.), however I want to make it into a UIButton. The idea being the the can press the map view and it will call a function, the same way pressing a UIButton does.
I've had a look around online for ideas on how to achieve this but I haven't found anything yet. I tried making a UIButton over the top of the map view but I can't seem to make it invisible. I also tried linking an IBAction to the map view, however the option to link it doesn't appear in the connections inspector (as I expected to be honest - shot in the dark!).
Is there any way to achieve this effect?
You can place a UIButton over the map, just like you tried before. But to make it invisible, change the button type from Round Rect to Custom. This will make the button invisible unless you explicitly add an image to the button.
-Cheers

Show a UINavigationBar back button without pushing a view controller

In the iPad's Photos app, when you tap an album the stack of pictures expands to fill the screen - you're in the same view, it's just rearranged the grid a little. But at the top, a left-arrow-style Back button appears, as if pushViewController had been used - except it fades in neatly, rather than sliding in. When you tap that, it fades out again, rather than sliding out.
Is there a way to replicate this behaviour? I've tried a few options so far, and might just be missing something. What I've tried:
Setting self.navigationItem's leftBarButtonItem works, but gives me a square button rather than an angled Back-style one - there are a few hacks online to make this work, such as using pictures for the button, but I'd rather only use them if there's definitely no "official" way to do this.
Setting self.navigationItem.backBarButtonItem - this is generally used to customise the back button when a view controller is pushed, so it has no effect.
[self.navigationController.navigationBar setItems::] - this works, although it gives me the sliding animation rather than fading. As a result, I use animated:NO to make it just appear. Downside: when tapping Back, you do get the sliding out animation, which looks weird because the rest of the UI stays still.
Has anyone managed to replicate this effect?
Thanks in advance!
Your first approach is probably the best.
It doesn't have to be super-hacky, you can use a normal UIButton and customize it to look like a back-button using backgroundImageForState: and titleForState: (etc.), then set the UIButton object as the customView of your UIBarButtonItem.
Many apps these days customize the look & feel of the buttons anyway, so using a custom background image is quite normal. If you use resizableImageWithCapInsets: (or stretchableImageWithLeftCapWidth:topCapHeight: if you need to support iOS earlier than 5.0) then the button can still stretch to fit whatever text goes inside, and as it's a normal UIButton the text is localizable, etc. I don't consider this approach to be hacky, it is a perfectly sensible way to get around the limited functionality of UIBarButtonItem objects.
Better late than never.
To show a back button without pushing a view controller, use pushNavigationItem:animated: and popNavigationItemAnimated: on UINavigationBar. These result in the standard slide animation and creation of a back button. However, there is no way to ensure your content animation runs for the same time as the bar animation other than making an educated guess at the duration.
Since iOSĀ 7 there is a better API for achieving this effect, where you still push and pop view controllers but you provide a custom transition animation through navigationController:animationControllerForOperation:fromViewController:toViewController: from UINavigationControllerDelegate. This allows the animations between the bar and content to be perfectly coordinated.
Finally, if your content before and after is managed by UICollectionViewController, you can use useLayoutToLayoutNavigationTransitions, which is designed for use-cases like Photos.

how to reload a view again and again

hi i am a new iphone programmer
i am creating a imagedisplay type application where i have to display images on a view and by presssing a next button a new image should appear on same view (i am using database)...
therefore i need to reload my current view again and again...each time when i click that button....
i tried some suggesion which are given on this website but not satisfied because many of them are based on timer...
please help.....
May be I have missed something in your question. But why you need to reload the entire view? You are using an UIImageView to display your image, right? And you are not showing any kind of scroll, but only a next button, right? Then why don't you just set the image property of UIImageView when the button is tapped.
// in button handler
myImageView.image = [UIImage imageNamed:#"new_image.png"];
Perhaps you could use a paged UIScrollView with three uIImageViews and always have the previous, current and next image loaded. This way when the user hits next, it scrolls animated to the next image. When page 3 is loaded, it programmatically sets the second image view as the desired next image, sets the image you came from on the first image view, and sets the scroll view non-animated to page two and loads the next image in the third image view.
Sounds complicated but basically you are giving the appearance of an infinite scroller but only pulling one image at a time except for initial load of three.
You could try looking at the "PageControl" Example Project in the XCode Documentation. It should give you a good starting point.

iphone - forcing button to acknowledge touch programmatically

When you touch a UIButton it hides for a fraction of second and then it executes its action. This fast "blink" is the feedback the user needs to know that the button has been clicked.
In the project I am doing, I need to select the button programmatically, as if the user had clicked it. In other words, the same behavior has the button had been clicked by the user... a fast blink and execution of its action.
Is this possible to do?
thanks for any help.
The change in the appearance of the button is effected by setting the button's highlighted property. The property is automatically set to YES when the user touches down on the button, and back to NO when she releases.
The highlighted property is writable, so you can set it YES yourself to simulate a touch down. You'll probably want to use +[NSTimer scheduledTimerWithTimeInterval:invocation:repeats:] to set it back to NO after a short interval.
It is pretty simple, and probably there is a better solution.
First, use images to your button, and when you have to fire the button, you just change the button's image in the normal state to the pressed image, and after that, replace it back to the original. You can simply do it with a timer.