I have a problem with google maps in ios. I have a screen with the MapView and I am drawing some annotations (polygones dispalying zones on the streets). If somebody taps the zone it gets selected a button shows up and the user can press it to start a transaction. He has to hold the button for 2s and in this time a small view with a progress bar is shown to indicate that the user has to hold it till it comes to end. This works fine. However sometimes after playing a bit following problem appears:
The View with the progress bar show up but disappears before it reaches the end. If try next time everything works smoothly. Here is the code that matters, I think:
- (IBAction)starButtonTouched:(id)sender {
self.progressLabel.text = [NSLocalizedString(#"Please hold", nil) uppercaseString];
if (!self.currentVehicle) return;
self.progressBar.hidden = NO;
self.progressBarBackground.hidden = NO;
self.progressBar.progress = 0;
[self performSelector:#selector(_updateProgress) withObject:nil afterDelay:kVTMainButtonPressDuration/kVTMainProgressSteps];
}
- (IBAction)startButtonReleased:(id)sender {
NSLog(#"StartButton released - progress bar will be hidden");
self.progressBar.hidden = YES;
self.progressBarBackground.hidden = YES;
}
- (void) _updateProgress {
if (self.progressBar.hidden) return;
/*
* update progress bar
*/
float actual = [self.progressBar progress];
if (actual < 1) {
self.progressBar.progress += 1.0/kVTMainProgressSteps;
[NSTimer scheduledTimerWithTimeInterval:kVTMainButtonPressDuration/kVTMainProgressSteps target:self
selector:#selector(_updateProgress) userInfo:nil repeats:NO];
/*
* if it has ended start the transaction
*/
} else {
ASLogInfo(#"Starting");
if (!self.currentVehicle) return;
[self.service startParking:self.currentVehicle zone:self.selectedZone callback:^(VTTransaction *transaction) {
[self loadCurrentTransaction];
}];
}
}
Does anybody have an idea what and why causes the View to disappear? Thanks a lot.
Bye,
Filip
Related
I am making a game with a boost button. Of course, just leaving it as enabled would allow the player to tap it constantly. So, I need a 20 second delay before it is possible to push the button again. Also, would it be possible to show this progression on the button, preferably on the button itself?
In the future please try to show what you have tried to solve your problem. However, since you are new I'm going to let it slide once!
This code uses a NSTimer that is called once per second. It will fire what ever code you specify for "Boost". It will also disable user interaction on your button until it has been 20 seconds from when the button was pressed at which point it will allow the user to press the button again, and finally, this code displays how many seconds remain until "Boost" can be used again on the titleLabel property of your button.
- (IBAction)buttonPressed:(id)sender
{
myTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(activateBoost) userInfo:nil repeats:YES];
}
- (void)activateBoost
{
if (myButton.userInteractionEnabled == YES) {
//Put your Boost code here!
}
if ([myButton.titleLabel.text intValue] == 0) {
[myTimer invalidate];
[myButton setTitle:#"20" forState:UIControlStateNormal];
myButton.userInteractionEnabled = YES;
}else{
myButton.userInteractionEnabled = NO;
int currentTime = [myButton.titleLabel.text intValue];
int newTime = currentTime - 1;
myButton.titleLabel.text = [NSString stringWithFormat:#"%d",newTime];
}
}
In order for the above code to work, you will need the declare a NSTimer named "myTimer" and a UIButton "myButton". You will also need to set the buttons initial text to "20".
I have a UIActivityIndicatorView middle on camera OverlayView.xib. I am taking multiple snap by calling [cameraPicker takePicture] repeatedly. I want to show the indicator when all snaps taking done by the bellow code:
- (void)didTakePicture:(UIImage *)picture { //Called from picker didFinishPickingMediaWithInfo
[self.capturedImages addObject:picture];
snapsCount ++;
if (snapsCount < noOfSnaps) {
[cameraPicker takePicture];
}else {
overlayView.indicator.hidden = NO; //Not showing indicator
[overlayView.indicator startAnimating]; //Not working
}
}
Can anyone tell me the reason why not showing.
I can show the indicator before taking the last snap by the following condition, but why not at last.
if (snapsCount < noOfSnaps) {
if (snapsCount+1 == noOfSnaps) {
overlayView.indicator.hidden = NO; //Show the indicator
[overlayView.indicator startAnimating]; //Work nicely
overlayView.userMessage.text = #"Processing";
}
[cameraPicker takePicture];
}
Is there anyone faced the problem and know the solution to show the indicator after all snap taking done.
Thanks in advance.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
if (snapsCount > noOfSnaps) {
overlayView.indicator.hidden = NO;
[overlayView.indicator startAnimating];
}
[NSTimer scheduledTimerWithTimeInterval:0.3
target:self
selector:#selector(didTakePicture:)
userInfo: [info objectForKey:UIImagePickerControllerOriginalImage]
repeats:NO];
}
I have this code in a button click [NSThread detachNewThreadSelector: #selector(spinBegininapp) toTarget:self withObject:nil]; to show a activity indicator for user that the background thread is running ,i put this code to enable the activity-indicator
- (void)spinBegininapp
{
_activityindictor.hidden = NO;
}
and it works fine,when i click the button it shows the activity-indictor animating ,when the thread goes it hides the activity-indicator,but my need is to show a progressView instead of activity-indicator,it progresses according to the thread,and if the thread finishes it need to reach progress completely and self hide.is that possible .
#pragma mark - Loading Progress
static float progress = 0.0f;
-(IBAction)showWithProgress:(id)sender {
progress = 0.0f;
_progressView.progress = progress;
[self performSelector:#selector(increaseProgress) withObject:nil afterDelay:0.3];
}
-(void)increaseProgress {
progress+=0.1f;
_progressView.progress = progress;
if(progress < 1.0f)
[self performSelector:#selector(increaseProgress) withObject:nil afterDelay:0.3];
else
[self performSelector:#selector(dismiss) withObject:nil afterDelay:0.2f];
}
-(void)dismiss {
[self progressCompleted];
}
now call the following function whenever/where ever you want to show progress
[self showWithProgress:nil];
progress range lies between 0.0 and 1.0
1.0 means 100%
you can add a progress view no doubt but usually it used for definite quantities like time or data.. for eg. If you are downloading a 2mb file then you can always tell how much data you have downloaded and show the in the progress view as a factor. So if something similar is happening inside your thread you can use this..
UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:whateverStyle];
progressView.progress = 0.75f;
[self.view addSubview: progressView]
[progressView release];
you just need to update your progress as the value changes.... hoping this helps.
Hi all im using progress bar for indicating the status of xml parsing in my app.but it is not showing the step by step updation,instead the progress bar is loading after the entire xml parsing is over,till that time it is stuck and not showing any progress.how to solve this issue.can anyone help me please.
I use the below code
IBOutlet UIProgressView * threadProgressView;
threadProgressView.progress = 0.0;
[self performSelectorOnMainThread:#selector(makeMyProgressBarMoving) withObject:nil waitUntilDone:NO];
- (void)makeMyProgressBarMoving
{
float actual = [threadProgressView progress];
if (actual < 1) {
threadProgressView.progress = actual + ((float)1/(float)10);
[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:#selector(makeMyProgressBarMoving) userInfo:nil repeats:NO];
}
else{
/* something else */
}
}
Create a timer on the main thread for every 1/10th of a second. Have it hit your "makeMyProgressBarMoving" function.
myTimer = [NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:#selector(makeMyProgressBarMoving) userInfo:nil repeats:YES];
Then edit your function to look like this:
- (void)makeMyProgressBarMoving {
float actual = [threadProgressView progress];
if (actual < 1) {
threadProgressView.progress = actual + ((float)1/(float)10);
return;
}
//if you got here that means the progress view is greater than 1 so now you can kill your timer that you had running every 1/10th of a second.
[myTimer invalidate];
}
-(IBAction) change {
self.imageView.animationImages = myImages;
self.imageView.animationDuration = 2;
if(self.imageView.isAnimating == NO){
[self.imageView startAnimating];
NSLog(#"if bool = %d", self.imageView.isAnimating);
}
else {
self.imageView stopAnimating];
NSLog(#"else bool = %d", self.imageView.isAnimating);
}
}
hello, i'm studying iOS programming.
but i have a question.
i have a button and when i click the button, then this method will be called.
first i click the button, then this code will start the if statement. that's what i want.
i click the button again, i think that will execute the else statement.
but it always execute the if statement only.
why is that?
i really don't know why is that. please help me
I think setting the properties like animationImages or animationDuration will stop the animation, so that by clicking, you every time stop and then just after (re)start it in the if part. Try setting these two properties outside the action method you wrote, and just let the if/else sequence.
-(IBAction) change {
// set these two anywhere else
//self.imageView.animationImages = myImages;
//self.imageView.animationDuration = 2;
if(self.imageView.isAnimating == NO){
[self.imageView startAnimating];
NSLog(#"if bool = %d", self.imageView.isAnimating);
}
else {
self.imageView stopAnimating];
NSLog(#"else bool = %d", self.imageView.isAnimating);
}
}