image change every a fixed time in iPhone - iphone

I have 4 images. I want to load image in first screen and change images after every 10 second. when we click any images than next screen come up.
please give me help i am new in iPhone.

Use NSTimer to trigger the image change. If the user taps an image and you want to stop the image rotation, you can invalidate the timer before switching to the next view.

You can try by creating a method that changes the image in the imageView and calling it using a NSTimer which repeatedly calls the method every 10 seconds.
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:#selector(changeImage) userInfo:nil repeats:YES];
- (void)changeImage {
// Change image here
}

HI Avinash,
I think you need below code...
******* IN VIEW DID LOAD
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:#selector(changeImage) userInfo:nil repeats:YES];
- (void)changeImage {
[self.imgview setImage:[UIImage imageNamed:#"test.png"]];
}
Thx

Related

Scroll UISlider Automatically

So currently I have a UISlider in a UIViewcontroller that is meant to start animations within subviews when the user slides.. Basically when the user slides I have this battery with a filling in it that fills the empty battery image with a bar to indicate power within a cell, and the user can slide to see the energy the battery has at certain times of the day.
At the moment, when the View loads I would like the UISlider to AUTOMATICALLY start sliding from the beginning of the slider and scroll to the end within, lets say 5 seconds.
I implemented a loop that cycles through all the values of the uislider using this loop
for (int i = 0; i < [anObject count] - 2; i++)
{
sleep(.25);
NSUInteger index = (NSUInteger)(slider.value + 0.5); // Round the number.
[slider setValue:index animated:YES];
}
[anObject count] - 2 is equal to 62 at this time of day but will change and increment every 15 seconds because I'm fetching data from a server.
But that aside, why doesn't this work? The loop?
EDIT:
So heres what I did with NSTIMER
[NSTimer timerWithTimeInterval:0.25 target:self selector:#selector(animateSlider) userInfo:nil repeats:NO];
and animateSlider looks like this:
- (void)animateSlider:(NSTimer *)timer
{
NSLog(#"Animating");
NSUInteger index = (NSUInteger)(slider.value + 0.5); // Round the number.
[slider setValue:index animated:YES];
}
But no luck... Why isn't NSTimer "firing"..... I remmeber vaguely there was a method that FIRES an nstimer method but not sure if that's needed...
EDIT:
Ahh it does need "Fire"....
NSTimer *timer = [NSTimer timerWithTimeInterval:0.25 target:self selector:#selector(animateSlider) userInfo:nil repeats:NO];
[timer fire];
But for some reason it only fires once.... Any ideas ?
"for some reason it only fires once..."
If you changed the NSTimer set up to this:
NSTimer *timer =
[NSTimer scheduledTimerWithTimeInterval:0.25
target:self
selector:#selector(animateSlider:)
userInfo:nil
repeats:YES];
This would schedule the timer on the current run loop immediately.
And since the "repeats" parameter is "YES", you'd then repeat the timer every quarter second, until you invalidate the timer (which you should do when the ending condition is reached, like when the slider reaches its destination).
P.S. You'd need to change the selector method declaration of your timer's target slightly. According to Apple's documentation, "The selector must correspond to a method that returns void and takes a single argument. The timer passes itself as the argument to this method."
So declare "animateSlider" like this instead:
- (void)animateSlider: (NSTimer *) theTimer;

How to take and save 20 photo in one second using objective c

I am creating one photo capture app in which user can take up to 20 photo in one second.
I have already try the AVCam Sample code of apple but it is don't allow to take still Image at 20 FPS.
Is there any other way to take photo at this rate.
see this Demo..Photo Picker
in this demo just check or refer these two classes..
MyViewController.m and
OverlayViewController.m
in OverlayViewController.m class in timedTakePhoto method just set timer with your requirement like bellow..
- (IBAction)timedTakePhoto:(id)sender
{
// these controls can't be used until the photo has been taken
self.cancelButton.enabled = NO;
self.takePictureButton.enabled = NO;
self.timedButton.enabled = NO;
self.startStopButton.enabled = NO;
if (self.cameraTimer != nil)
[self.cameraTimer invalidate];
_cameraTimer = [NSTimer scheduledTimerWithTimeInterval:0.03
target:self
selector:#selector(timedPhotoFire:)
userInfo:[NSNumber numberWithInt:kOneShot]
repeats:YES];
// set time with your requirement above
// start the timer to sound off a tick every 1 second (sound effect before a timed picture is taken)
if (self.tickTimer != nil)
[self.tickTimer invalidate];
_tickTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:#selector(tickFire:)
userInfo:nil
repeats:YES];
}
may you can get idea from this and also use this demo for your requirement..
i hope this help you...

Cocos2d Timer to delete objects

Im trying to create a timer in Cocos2d in which an object is created and deleted 5 seconds after it is created. Does anyone know how to make this?
I'm assuming you mean you are trying to delete a CCSprite when you said object. You setup a timer to call a method which then deletes the sprite by the tag number that you assigned it when you created the sprite (lets pretend you assigned the tag number 10 for the example below)
[self schedule: #selector(delete) interval:5];
-(void)delete{
[self removeChildByTag:10 cleanup:YES];
}
Alternatively, You can use NSTimer like this :
NSTimer * timer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:#selector(removeSprite) userInfo:nil repeats:YES];
-(void)removeSprite {
[self removeChild:spriteName cleanUp:YES];
}

I want to call a method after particular time until my app opened in iphone?

I want to call a method after each 2 minutes,
how can I apply such logic?
Use an NSTimer object. It's been talked about quite a lot here, so I won't repeat all that - just search for "NSTimer" in the search box at the top right. :-)
You can use a timer..
[NSTimer scheduledTimerWithTimeInterval:120.0 target:self selector:#selector(yourFunction:) userInfo:nil repeats:YES];
.........
..........
-(void)yourFunction:(NSTimer*)timer{
//do your action here
}
I use a NSTimer to trigger a method. I use the below code in my initial viewDidLoad section:
myTimer = [NSTimer scheduledTimerWithTimeInterval:120.0 target:self selector:#selector(theMethod) userInfo:nil repeats:YES];
Hope that helps.

how to get back in navigation view

hi i am new to iphone application. i am doing an application that consist of image picker and image view. i am displaying the image in imageview by selecting the image in image picker .. what i need is afetr 3 seconds i have to go back imagepicker how can i done this please give code for that
You want to create an NSTimer object.
NSTimer *theTimer = [NSTimer scheduledTimerWithTimeInterval:3.0
target:self
selector:#selector(pictureTimerFired:)
userInfo:nil
repeats:NO];
Where the target selector has a signature like:
- (void) pictureTimerFired:(NSTimer*)theTimer {
NSLog(#"Timer fired, closing picture");
}
You would remove the imageView in the opposite way you added it. i.e. it depends if it was added as a modal view or subview etc.