Saturday, February 13, 2010

Implementing Tap and Hold on the iPhone

In the Apple Developer guide there is some good sample code for implementing the tap and double tap. We've written about that in a previous blog post so won't go over it again here. For something we're doing now, we want to show a little tool palette when the user taps down and holds their finger on the screen. The way we're doing this for now is just to rearrange the code that we use in other applications for tap and double tap.

In the - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event event we call our method to display the palette with a delay of .3. That line looks like this

[self performSelector:@selector(showtheTools:) withObject:buttons[i] afterDelay:0.3];


In our - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event event we first call a cancel of the delay and then perform an action for single tap. The code to cancel the delayed event is

[NSObject cancelPreviousPerformRequestsWithTarget:self];


Our thinking here is that once the tool palette is displayed there is no PerformRequest to cancel so nothing is done. In our touchesEnded even we have one more thing. If the tool palette is displayed, it sets an instance variable. touchesEnded checks that variable and only performs the single tap code if that variable indicates that the palette was not displayed.

UITouch *touch = [touches anyObject];

[NSObject cancelPreviousPerformRequestsWithTarget:self];

if (paletteIsDisplayed == NO) {

if(([touch view] == buttons[i])){

self.touchedButton:buttons[i];

}

}



One of these days, I wish Apple would publish a library of the best practice patterns for handling basic touch gestures. I know that a gesture library is a feature in other O/S and I would love to see it here.

Thursday, February 4, 2010

iWeb and SEO two different worlds

I am trying to use iWeb, I really am. I just get really frustrated with it sometimes. So, apologies to anyone who is currently taken aback by the amateur look to my navigation. I'm having to recode the nav bar and then push it into iWeb. I am using the approach taken over at All About Web for fixing the iWeb nav bar.

Sometimes iWeb is like that person you used to date: really pretty but such high maintenance.

So now, after I make my pretty pages in iWeb, I have to load each page into TextWrangler to add my keywords and google tracking code. Then ftp everything over by hand. I had been using the RAGE iWeb SEO tool to add keywords but it died during its most recent update and I just haven't had a chance to see if it was the tool that died or something with my computer.

Anyway, as my old affair with FrontPage devolved into Notepad and the command line, my recent fling with iWeb seems to be slowly morphing into vi/TextWrangler/Terminal. These kind of programs (iWeb and FrontPage) have a real place in the computer world as they are helping move the whole everyone-is-a-publisher democratization of content. However, when they try to "help" me with my pages, they often don't.