How to create a scrolling image gallery in iOS? - ios

In my app, I have 5 images, and 2 buttons(next and previous).
I have stored those images in an array.
When next button is pressed, I want to remove the current image and display the next image, and for previous button, it is vice versa.
I have done this using the code.
-(void)nextButton:(id)sender
{
if (i < (array.count-1))
{
i=i+1;
imageView.image = [images objectAtIndex:i];
}
}
-(void)previousButton:(id)sender
{
if(i >= 1)
{
i=i-1;
imageView.image=[images objectAtIndex:i];
}
}
Now, my doubt is, when the image changes, there happens no animation, simple the next image replaces the previous image.
But, my request is when I click the button, the previous button should decrease by the width and move out of the imageView and the next image should come inside the imageView gradually like this

I understand it and it looks like you would need some custom animation, check out it has various animation and u can use anyone you like

Currently you are just simply assigning image to the imageview. that's why there is no animation. For this animation, you can use the below library
http://code4app.net/ios/iCarousel-for-Cover-Flow/4f87d2db06f6e79d32000000

I guess you need a cover flow effect. Try browsing iCarousel. Try link below, it provides great options for different style
https://www.cocoacontrols.com/controls/icarousel

use iCarousel .. in this you will have # 7 types of animation. if you don't want to use 3rd party code. Better option is fade-out current image and fade-in new image.

Related

How to make a UIImageView repeat forever across the screen [x-axis]

I am developing a game on xCode, but I ran into a problem.
I was able to make the UIImageView move <------- left across the iPhone screen, but it I want it to repeat as soon as it begins to move so it could look endless.
Lets say that one piece of the floor in that app is a UIImageView, how can I make that UIImageView repeat across the screen [x-axis] as shown in that app. [NOT MY APP]
-(void)whiteFloor{
whiteFloor.center = CGPointMake(whiteFloor.center.x-1);
if(whiteFloor.center.x < 130){
[self placeGround];
}
}
-(void)placeGround {
// Also would I need to make a int?
//what would write here
}
I'm sure there are better ways to do it if you use SpriteKit, but if you don't want to use it, you can maybe use 2 UIImageView one after another to create the endless effect.

C4 stepper custom images

I'm trying to use my own images on a C4Stepper. I'm setting it up like this
#implementation C4WorkSpace{
C4Stepper *theStepper;
C4Image *stepperBackground;
C4Image *stepperPlus;
}
-(void)setup {
//load backgroundimage
stepperBackground=[C4Image imageNamed:#"icon_zoom.png"];
stepperBackground.width=100;
//load incrementImage
stepperPlus=[C4Image imageNamed:#"icon_zoom_plus.png"];
stepperPlus.width=stepperBackground.width/2;
//setup stepper
theStepper=[C4Stepper stepper];
[theStepper setBackgroundImage:stepperBackground forState:NORMAL];
[theStepper setIncrementImage:stepperPlus forState:NORMAL];
theStepper.center=self.canvas.center;
[self.canvas addSubview:theStepper];
}
The 2 icons look like this:
Strangely, what appears on the canvas looks something like this: !
Are there any special requirements for the zoomStepperImages? A certain size or something?
There are special requirements.
The background image used is "stretchable", so you have to design a button image that can be stretched if needed. If you have a look at any of the button images (incl. in the Media.xcassets folder) you'll see that they are generic. For example, the selected button background image looks like:
Similarly, the increment / decrement images are themselves independent of the background images. The incrementNormal image included in the same folder looks like:
You can see how the default values of the C4Stepper class are initialized in C4AppDelegate.m:
...
[C4Stepper defaultStyle].style = basicStyle;
[C4Stepper defaultStyle].tintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"lightGrayPattern"]];
[[C4Stepper defaultStyle] setDecrementImage:[C4Image imageNamed:#"decrementDisabled"] forState:DISABLED];
[[C4Stepper defaultStyle] setDecrementImage:[C4Image imageNamed:#"decrementNormal"] forState:NORMAL];
[[C4Stepper defaultStyle] setIncrementImage:[C4Image imageNamed:#"incrementDisabled"] forState:DISABLED];
[[C4Stepper defaultStyle] setIncrementImage:[C4Image imageNamed:#"incrementNormal"] forState:NORMAL];
So, what you want to do is create an image for your background (mine is stretchable because the stuff in the middle are straight lines that can be stretched horizontally without looking stretched. You also want to create independent + - images for increment / decrement sides of the button.
Just as a note, when I was creating the C4Button class, I had to play around with the various images I was creating to get them to "look" right... In the end, I had to do a lot of tweaking and experimenting to learn how they were rendered. The difficulty I had in figuring this out was that the rendering mechanism of UIButton itself was a bit strange and I had to learn how to fit things into the button so that they rendered properly.

How do I change an Image when a button is pressed?

Now I know this question may sound like a duplicate, but I doubt it seeing as I've researched and none of the possible duplicates answer my question. If it is a duplicate and it's been answered by all means show me the way!
But my question doesn't deal so much with a button changing an image, more so the button is the image.
So my button is an image and when pressed a sound plays and then the image changes until the sound is done. My problem is I can't get the image to change.
Now I have tried this method thinking that I could press my button and my new image would cover up my button until the sound was done:
UIImage *dolDerp = [UIImage imageNamed:#"dolphin2.png"];
[imageview setImage:dolDerp];
I have an outlet set up and it's connected to an image view object and then the action is connected to the button, so in theory when the button is pressed the new image should take over the screen. Now obviously the code needs to be tweaked so the button would go away after a few seconds when the sound is played, but my problem is I can't even get the button to display. I also would prefer to just have the button objects image change if possible?
If anyone could offer some help it's much appreciated!
the best thing is in Interface Builder assign the two images to the button Normal/Selected states.
in code just use this line:
myButton.selected = YES;
//or
myButton.selected = NO;
What #Mahmoud Fayez suggested is good. In code, the proper way to set a buttons image/background image is [button setImage:image forState:UIControlStateNormal] or the similar method for setBackgroundImage
If you are using IB though, it is indeed best to set the different images for different states in IB, then change the buttons state (which will then change the buttons image) in code.

What exactly IS the highlighted image in a UIImageView?

This question boggles my mind and I cannot find an answer. I looked all over the documentation, tried out code, and searched Google, but I can't find anything. The UIImageView in iOS programming can have an image set to it, but you can also set a highlighted image to it. What exactly is this highlighted image?
you can set two different images to an UIImageView, one to its image property, another to its highlightedImage property.
There are many cases where you want to change the state of the image (eg: a checkmark) from off to on or vice versa. in that case, instead of you setting the UIImageView's image to the appropriate one everytime, you can just say
theCheckMarkImageView.image = regularImage;//set the regular image
theCheckMarkImageView.highLightedImage = highlightedImage;
(based on your logic show it highlighted or not).
theCheckMarkImageView.highlighted = YES/NO;
In addition to all this, do check Ethan Huang's answer about how tabelviewcell works with this property. Quite useful if you are showing different images based on cell selection.
highlightedImage use for highlight ImageView,simple.
imageView.highlightedImage = [UIImage imageNamed:#"hightlighted.png"];
imageView.highlighted = YES;
Don't need to waste time to search or read a lot. Objective-C is meaningful language. Just drag ImageView and make a try code, step by step test all property, method in UIImageView.h(in UIKit framework) and you'll understand.
Do the same with other UI element.
Besides Nitin Alabur's answer, a useful tip here:
UITableViewCell or UICollectionViewCell has a .selected property. If you put an UIImageView in a cell, then, when you select the cell, the imageView will use the .highlightedImage instead of .image.
Thus you can make cell selection visual state easily.
The highlighted image is for when you have a control that has a UIImageView that can be pressed. While the user is pressing the control, the highlighted image is shown. When the control is not being pressed, the normal image is shown.
All commenters have been wrong or answered the wrong question or been too wordy. Here's the simple and correct answer:
The highlighted image state is when the user's finger is touching the imageview.

Animate a switch using an image sequence

I would like to know how to solve a problem I'm having. I have an image sequence that basically animates a switch.
I'd like to implement this in iOS. How would you advise me to go for that? Maybe using UIButton? Or rather UISwitch?
For a rather simple solution (tap switches, no swiping possible), I would advise you to use two UIViews stacked.
-1- At the bottom, use a UIImageView which allows you to run image animations.
-2- At the top, use a UIControl which will capture the touché-up-inside events.
Alternatively, you could use a UITapGestureRecognizer as a replacement for -2-. The latter option should only be considered if the resulting control will not be used for iOS < 3.2.
As soon as your tap-recognizer (UIControl or UITapGestureRecognizer) receives the tap-event, you simply play the animation provided through your UIImageView.
For more details on animations using UIImageView see its class reference, specifically on things like animationImages (an array of images).
As UIImageView does not provide you with a reverse animation feature, you will have to assign the images in the reverse order before animating back to the start (that is after a user switched it on and now switches back to off).
For a more complex solution (tap switches, swiping is possible), you may add a UISwipeGesture Recognizer to your custom control and use the status of that UIGestureRecognizer to select the currently visible image of your UIImageView.
iOS 5 allows you to make animated UIImages. You can put the animated UIImage right into the UIButton and animate it on button presses. Animated UIImage

Resources