I am running XCOde 5, ios7.
I created a UIImage in the Storyboard.
If I set the .image property using:
self.image43.image = [UIImage imageNamed:self.string4];
in ViewDidLoad(), it WORKS FINE!
If, however, execute the exact same code inside my gameplay routine (the routine have setup as my timer selector as shown below), it does not display.
self.myTImer = [NSTimer scheduledTimerWithTimeInterval:1.0/30.0 target:self selector #selector(gameplay:) userInfo:nil repeats:YES
I'm sooooo close to being done..... :)
THanks
-Ed
Related
I am making a game and currently my "player" is animating as I've implemented (which is wrong at the moment) and it continually runs the animation from start to start because it always restarts from the beginning when the function is called. What is the best way to prevent this and let the animation run all the way through? Here is the code I'm using at the moment:
- (void) startAnimatingLeft
{
NSArray *images = [NSArray arrayWithObjects:img9,img10,img11,img12,img13,img14,img15,img16, nil];
[imageView setAnimationImages:images];
[imageView startAnimating];
animateTimer = [NSTimer scheduledTimerWithTimeInterval:0.6 target:self selector:#selector(nothingMovingLeft) userInfo:nil repeats:NO];
}
From UIImage documentation:
startAnimating
This method always starts the animation from the first image in the list.
So you shouldn't call this method if the image is already animating. You can call isAnimating method to check if image is animating.
I'm trying to write some objective-c code that allows capture of frames through the iPhone camera, after a specific time delay. Any examples I have found online have captured the 'present' frame input by the camera (i.e. a realtime frame capture). I am looking for a less real time frame capture - a way to capture frames with a specific time delay. Any ideas?
I would use NSTimer.
It would allow you to use the code that captures the current frame, and it would get called after a delay.
You can create a non-repeating timer like this: timer = [NSTimer scheduledTimerWithTimerInterval:delay target:self selector:#selector(capture) userInfo:nil repeats:NO]; where delay is the specific time delay and capture is a method that contains the code from an example that captures the present frame.
Use following code.....
//call method according to your delay that you need.....
float yourdelay;
yourdelay = 0.7;
[self performSelector:#selector(captureView) withObject:nil afterDelay:yourdelay];
// or set time for calling method....
[NSTimer scheduledTimerWithTimeInterval:0.02 target: self selector:#selector(captureView) userInfo:nil repeats:NO];
///or you can call method directly when you need..
[self captureView];
////Here the code for capture real time image.
- (void)captureView {
UIGraphicsBeginImageContext(mapView.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
flickerImaveView.image=viewImage;
}
Hope this will help you....
When i push the button I would like the first image to show in the UIImageView, stay for a short period of time and then the next image to show. Only the second image shows after a period of time. The first image never comes on.
// TestProjectViewController.m
// Created by Jack Handy on 3/8/12.
#import "TestProjectViewController.h"
#implementation TestProjectViewController
#synthesize View1= _view1;
#synthesize yellowColor = _yellowColor;
#synthesize greenColor = _greenColor;
- (IBAction)button:(id)sender {
_greenColor = [UIImage imageNamed: #"green.png"];
_view1.image = _greenColor;
[NSThread sleepForTimeInterval:2];
_yellowColor = [UIImage imageNamed: #"yellow.png"];
_view1.image = _yellowColor;
}
#end
U can try and place the
_yellowColor = [UIImage imageNamed: #"yellow.png"];
_view1.image = _yellowColor;
and instead of the
[NSThread sleepForTimeInterval:2];
call this one
[self performSelector:#selector(changeColor) withObject:nil afterDelay:2];
The problem here is that you are replacing the image before the OS gets a chance to draw. Since all of these three operations: change the image, wait 2 seconds, change the image again) occur before your button action returns, you are preventing the Main thread from executing and thus the screen from refreshing. So, what's happening is that after 2 seconds, the screen draws with the image you most recently put in its place.
You need to have the waiting happen separately. There are three typical ways to do this, each of which have their benefits:
- send yourself a delayed message using -performSelector:withObject:afterDelay:
- spawn another thread or use a dispatch queue to run a thread in the background for the sleep and then send the message to the main thread from there
- or, use a timer.
My suggestion would be to use the timer, because it is easily cancelable if you need to do something like move to another screen.
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target: self selector: #selector(updateColor:) userInfo: nil repeats: NO];
// store the timer somewhere, so that you can cancel it with
// [timer invalidate];
// later as necessary
and then later:
-(void)updateColor:(NSTimer*)timer
{
_yellowColor = [UIImage imageNamed: #"yellow.png"];
_view1.image = _yellowColor;
}
If you want the colors to alternate, you can pass YES for the repeats: value in the creation code and then change -updateColor: to alternate... or move to the next color.
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
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.