It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
How to decrease points every seconds (for eg. Question 1: having 10 points) with respect to NSTimer ?
I have decrease to this points till 15 seconds only.
Thanks in advance.
Put this in your interface
#interface ViewController : UIViewController {
NSTimer *timer;
int seconds;
}
#property(nonatomic, strong) NSTimer *timer;
And this in your implementation where you need it
- (void)viewDidLoad
{
[super viewDidLoad];
self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:#selector(timerTick:) userInfo:nil repeats:YES];
seconds = 1;
}
- (void)timerTick:(id)sender{
NSLog(#"%d",seconds);
if (seconds == 15) {
[self.timer invalidate];
}
seconds++;
}
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
If I have this code below to tell the UIPicker if nothing is selected to set the feet to 1, How can I delay this action a few seconds?
// If feet values are zero.
if (([feetPicker selectedRowInComponent:0] == 0 & [feetPicker selectedRowInComponent:1] == 0)){
// Set to one foot.
[feetPicker selectRow:1
inComponent:1
animated:YES];
}
[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:#selector(fireMethod) userInfo:nil repeats:NO];
The above code can be placed whenever you want to start the timer.
-(void)fireMethod {
// If feet values are zero.
if (([feetPicker selectedRowInComponent:0] == 0 & [feetPicker selectedRowInComponent:1] == 0)){
// Set to one foot.
[feetPicker selectRow:1
inComponent:1
animated:YES];
}
}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to take a photo and as soon as i do that, the audio should start recording automatically for say, 3 seconds.
Those 3 seconds should be counted down by a timer which appears on the left side of the screen, after the photo is taken.
So, then i have to combine the image and audio together and save it in a private directory.
Could someone tell me how do i do this by using the AVFoundation and Audio Toolbox frameworks?
I don't normally work with AVFoundation so I don't know the exact method/class names (I filled in my own), but a workaround to this would be having a recurring NSTimer beginning when the recording originally starts. Something like this:
#interface
int rec_time;
NSTimer *timer;
Recorder *recorder;
#end
#implementation
-(void)beginRecording {
[recorder startRecording];
timer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:#selector(recordingTime)
userInfo:nil
repeats:YES];
}
-(int)recordingTime {
if (rec_time >= 10) {
[recorder endRecording];
[timer invalidate];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"You recorded for too long!";
return;
}
rec_time = rec_time + 1;
}
#end
Also
AVAudioRecorder has the following method:
- (BOOL)recordForDuration:(NSTimeInterval)duration
I think that will do the trick!
http://developer.apple.com/library/ios/#documentation/AVFoundation/Reference/AVAudioRecorder_ClassReference/Reference/Reference.html#//apple_ref/doc/uid/TP40008238
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want that i have 4 values in UISlider and i want that bydefaul values one should be selected when the application is loaded how to make that.
I want that when loaded it shows initial values.
slider=[[UISlider alloc] initWithFrame:CGRectMake(290, 152, 160, 36)];
slider.minimumValue=0;
slider.maximumValue=3;
[slider addTarget:self action:#selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
Slider Event
-(IBAction)sliderAction:(id)sender
{
NSString*testing=[[NSString alloc] initWithFormat:#"%d",(int)slider.value];
if([testing isEqualToString:#"0"])
{
sliderLabel.text=#"5 (gal/acre)";
sliderValue=#"5";
}
else if([testing isEqualToString:#"1"])
{
sliderLabel.text=#"10 (gal/acre)";
sliderValue=#"10";
}
else if([testing isEqualToString:#"2"])
{
sliderLabel.text=#"15 (gal/acre)";
sliderValue=#"15";
}
else
{
sliderLabel.text=#"20 (gal/acre)";
sliderValue=#"20";
}
}
If you need the slider to be able to select the discreet value 0.0, 1.0, 2.0 or 3.0, you may need to handle two of the controller events:
[slider addTarget:self action:#selector(handleSliderValueChanged:) forControlEvents:UIControlEventValueChanged];
[slider addTarget:self action:#selector(handleSliderTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];
The former needs to control the value change and the latter fix the slider pin position after the user will remove his finger.
To get the discreet slider value we can round it up:
- (float)roundedSliderValue:(UISlider *)slider
{
return roundf([slider value]);
}
When user is moving the slider we need to get the discreet pin position:
- (void)handleSliderValueChanged:(UISlider *)slider
{
int idx = (int)[self roundedSliderValue:slider];
switch (idx) {
// update UI
}
}
After the use did finish moving the slider we need to correct the pin position and save the value in defaults
- (void)handleSliderTouchUpInside:(UISlider *)slider
{
float val = [self roundedSliderValue:slider]
[slider setValue:val animated:YES];
[[NSUserDefaults standardUserDefaults] setFloat:val forKey:#"SliderValue"];
}
You can use the NSUserDefaults to store the selected value as default and load it on viewDidLoad
- (void)viewDidLoad
{
[super viewDidLoad];
float sliderVal = [[NSUserDefaults standardUserDefaults] floatForKey:#"SliderValue"];
[self.slider setValue:sliderVal];
}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to fire some method on voice detection.
For Example,
Just like in PragDuck app, When user starts speaking duck starts its animation.
How can I detect users voice?
Use AVAudioRecorder - Audio Metering - checkout out this tutorial - dettect when a user blows into mic http://mobileorchard.com/tutorial-detecting-when-a-user-blows-into-the-mic/
Quick Example:
_audioRecorder.meteringEnabled = YES;
//1. This method will get the current mic activity and will format it to a 0 - 1 scale.
-(void)checkRecordingMeters:(NSTimer *)timer
{
[_audioRecorder updateMeters];
const double ALPHA = 0.2;
float peakPower = [_audioRecorder peakPowerForChannel:0];
double peakPowerForChannel = pow(10, (0.05 * peakPower));
lowPassResults = ALPHA * peakPowerForChannel + (1.0 - ALPHA) * lowPassResults;
NSLog(#"Meters: %f" , peakPower);
NSLog(#"lowPassResults: %f \n" , lowPassResults);
}
//2. Call this method to run a loop timer to check the current mic activity
-(void)enableMettering:(BOOL)enable
{
if(enable)
{
levelTimer = [[NSTimer scheduledTimerWithTimeInterval:0.03
target:self
selector:#selector(checkRecordingMeters:)
userInfo:nil
repeats:YES] retain];
}
else
{
[levelTimer invalidate];
[levelTimer release];
}
}
You may use AudioQueue to record and add a simple threshold filter to ignore environment noise. For lower latency, you may use AudioUnit.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
So I've seen it everywhere in apps/games and other things its when you score or you get game over and the score number adds up to your score from zero. I want it so in about 1 second a label goes from the text: 0 to and integer that is stored with the players score.
Create a UILabel to display the score, and use an NSTimer to update the UILabel's text property. Apple doesn't ship a class that will do it all for you.
You need two variables; the currentScore and the current score being displayed. You will also need a timer to handle updating the ui.
When your score changes, update currentScore to the final score you want. Then start a timer that increments the displayedScore until it gets there i.e.
-(void)scoreUpdater:(NSTimer *)timer {
// Update the score
displayScore ++;
[scoreLabel setText:[NSString stringWithFormat:#"%i", displayScore]];
// Have we got there yet?
if (displayScore == currentScore) {
[scoreTimer invalidate];
[scoreTimer release];
scoreTimer = nil;
}
}
I would go by using an NSOperation that sleeps and add the points (actually it may work even without sleeping). Something like:
NSInvocationOperation *op = [[NSInvocationOperation alloc] initWithTarget:self
selector:#selector(updateScore)
object:nil];
[queue addOperation:[op autorelease]];
-(void)updateScore {
while (tot < 1.0) {
displayingScore += score*incr;
tot += incr;
// update score label to displayingScore
[NSThread sleepForTimeInterval:0.05];
}
}