How can I stop my UIWebView from automatically scrolling on the press of a button?
[web_try loadHTMLString:[NSString stringWithFormat:#"<marquee scrollamount='2' direction='up' loop='true' width='278' height='48'> <font size='3' face='HelveticaNeue-Bold' color='#242424'>%#</font></marquee>", option_value] baseURL:final_url];
i think you can use this code to scroll your view and to stop it just works fine for me
-(void)scrollView
{
NSInteger scroll = 1;
NSString* javascript = [NSString stringWithFormat:#"window.scrollBy(0, %d);",scroll];
[self.currentView stringByEvaluatingJavaScriptFromString:javascript];
if(validateTimer)
{
[timer invalidate];
validateTimer = false;
}
timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:#selector(scrollView) userInfo:nil repeats:YES];
validateTimer = true;
}
-(IBAction)stopScroll
{
[timer invalidate];
validateTimer = false;
hidden.enabled = FALSE;
}
use -
EDIT -
webView.scrollView.scrollEnabled = NO;
webView.scrollView.bounces = NO;
Here, I think you want to stop scrolling the content of web view. Check code. You have used "marquee" tag which is not controllable by objective c code.
Related
Now that my project automatically reloads (with help form someone on this site :D ) how could i get another but to stop reloading?
this is what i have:
-(IBAction)SendGPSData:(id)sender {
NSURL *myURL =[NSURL URLWithString:#"http://www.google.co.uk"];//<<change this!!!
NSURLRequest *myRequest = [NSURLRequest requestWithURL:myURL];
[myWebView2 loadRequest:myRequest];
[myWebView2 reload];
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:#selector(WebViewLoad:) userInfo:nil repeats:YES];
}
-(IBAction)stop:(id)sender {
//what do i put here to stop it reloading?
}
-(void)WebViewLoad:(NSTimer *)theTimer
{
[myWebView2 reload];
}
dont like asking another question so soon but im a total beginner to Xcode so any help will be great :)
Iv tried the myWebView stop loading;
but the original seems to override this :(
You can stop like this:
-(IBAction)stop:(id)sender {
[webView stopLoading];
}
You also need to stop the timer. So you do:
NSTimer* reloadTimer; // Put this in your class.
reloadTimer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:#selector(WebViewLoad:) userInfo:nil repeats:YES];
-(IBAction)stop:(id)sender
{
[reloadTimer invalidate];
reloadTimer = nil; // Prevents crash, when this method is called twice:
// reloadTimer is released when you call invalidate,
// so next time invalidate would be called on non-existing
// object -> crash.
[myWebView2 stopLoading];
}
It may make sense to put the code that starts/creates the timer in a separate method, so that you can use it restart the reloading again.
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];
}
I'm looking for the cleanest way to have a countdown timer fire when a user hits the 'take picture' button. Is there any easy way to do this?
One solution I'm thinking of is to just have a label that updates every second, but is there a way to get it working like Photobooth?
Also, at the last second before the photo is about to be taken I'd like for an image to be displayed briefly while the image is being taken. How can I go about this?
Any help would be great, thanks!
- (IBAction)takePicture:(id)sender {
theTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:#selector(updateLabel:) userInfo:nil repeats:NO];
}
- (void)updateLabel:(NSTimer *)timer {
_timeLabel.text = [NSString stringWithFormat:#"%d", time];
time = time - 1;
if (time == 0) {
[theTimer invalidate];
[_timeLabel performSelector:#selector(setText:) withObject:#"Photo taken!" afterDelay:1.0];
//Code for image shown at last second
} else {
theTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(updateLabel:) userInfo:nil repeats:NO];
}
}
Hope this helps ;)
I'm struggling with this. I saw some code where you can do this :
- (void)startTimer {
pauseTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(doActions) userInfo:nil repeats:YES];
}
Then call it in doActions.
Problem is i want to call it while a button is being pressed, and do actions is an IBaction. I keep getting a sigAbrt.
Can someone give me some sample code where you cay change a label from 'on' to 'off' every 1 second while a button is being pressed?
EDIT
i mean if doActions looks like this
- (IBAction) doActions {
for(int j; j<100; j++){
theLabel.hidden != theLabel.hidden;
//Does invalidate timer go here?
}
}
It still isn't clear to me, what you're trying to accomplish: I would have found it much easier, if you simply had it written down in plain english, after all.
That said, here's what I think will get you where you want to go:
// Assuming ivars:
// NSTimer* toggleTimer
// NSUInteger toggleCount
- (void)toggleTimerFired:(NSTimer*)timer
{
if ( toggleCount++ >= 100 ) {
[self stopToggling:self];
return;
}
// do whatever you need to do a hundred times here
}
- (IBAction)stopToggling:(id)sender
{
[toggleTimer invalidate], toggleTimer = nil; // you don't want dangling pointers...
// perform any other needed house-keeping here
}
- (IBAction)startToggling:(id)sender
{
[self stopToggling:self]; // if `startToggling:` will NEVER be called when a timer exists, this line CAN be omitted.
toggleCount = 0;
toggleTimer = [NSTimer scheduledTimerWithTimeInterval:1. target:self selector:#selector(toggleTimerFired:) userInfo:nil repeats:YES];
}
Depending on what exactly you want to do, startToggling: needs to be sent on either touchUpInside or touchDown. In the second case, stopToggling: probably needs to be called on any touchUp... event of the button.
- (void)startTimer {
pauseTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(doActions) userInfo:nil repeats:YES];
}
- (void) doActions {
theLabel.hidden != theLabel.hidden;
}
Does anyone know how to make a UILabel appear letter by letter like you can see in some games or other.
thanks
Set up an NSTimer to set the text property of the UILabel.
-(void) revealTimer:(NSTimer *)inTimer {
if ( ++mIndex < [mFullString length] ) {
mLabel.text = [mFullString substringToIndex:mIndex];
} else {
mLabel.text = mFullString;
[inTimer invalidate];
}
}
start it up with something like this:
-(void) revealString:(NSString *)inString {
mIndex = 0;
mLabel.text = "";
mFullString = [inString retain];
[NSTimer scheduledTimerWithTimeInterval:0.125 target:self selector:#selector(revealTimer:) userInfo:nil repeats:YES];
}
be sure not to leak mFullString as the above does, and store the timer if you may need to invalidate it.