Tagged with iphone

More about get rid of toolbar at iPhone Safari

When you visit some web site like Google Reader or Delicious at iPhone Safari, maybe you will notice that after have loaded page, the browser will hide tool bar automatically. This feature can save phone’s valuable screen space. To implement it we can just use javascript: window.scrollTo(0,1). See here, and here.

<script type="application/x-javascript">

if (navigator.userAgent.indexOf('iPhone') != -1) {
 addEventListener("load", function() {
 setTimeout(hideURLbar, 0);
 }, false);
}

function hideURLbar() {
 window.scrollTo(0, 1);
}

</script>

In common sense, it works. But if it didn’t, this article will help you.

First if we want toolbar hidden, beside the above JavaScript, below two conditions should be true:

1) web page is long enough. If it is short, the browser will think it is not necessary to hide the bar. You can zoom the page to test this rule.

2) scrollTo after page updated. setTimeout is used for this. We often invoke an AJAX to get HTML text from server and then update some part of page. The updating action will reload page so window.scrollTo must be invoked after AJAX has gotten response and page has been updated. So the timeout of scrollTo should be bigger than timeout of Ajax. Or invoke scrollTo after had gotten response directly. Keep in mind that setTimeout and Ajax both are asynchronousI used jQuery and $(#id).html(“<div>…”); to update page, so for DRY, I override this function:

if (navigator.userAgent.indexOf('iPhone') != -1) {
 (function ($) {
 var originalVal = $.fn.html;
 var hideURLbar = function() {window.scrollTo(0,1);};
 $.fn.html = function(value) {
var ret = originalVal.call(this, value);
 if (typeof value != 'undefined') {
 // setter invoked, do processing
 setTimeout(hideURLbar, 100);
 }
 return ret;
 };
 })(jQuery);
};

I found this cool script from here. Mabye this approach impacts app much, for html method is used everywhere in app. So take care before apply it. There is another option: use $(document).trigger to sent event.
Screenshot 2010.05.08 14.39.26

Tagged

终于成为iphone开发者了

android上面苦熬和观望一年后,上个月申请开发者,25$,但是没想到被据了,很是不爽,一气之下投奔iphone(虽然我对object c一窍不通)。

花了99$。注册过程很简单,麻烦的地方就是要传真下,网上有的攻略说要3个星期才能申请下来,N多TIPS云云。其实很简单。2天OK。无语。

资讯发达后,特别是类似“百度知道”这种问答类的网站的出现,确实提供了很多便利。但是也让人屁大的事情都要到网上google一下,结果人云亦云,没有主见,买个硬盘前做很多功课,货比三家,还特别迷信某些blog的评测数据。无聊之级!

说远了。付了99$后就可以下载iphone os 4 beta了,终于看到了传说中的mutil-task(双击home按钮,android上是长按),当然,是在模拟器上的。

五一去买个ipod touch 32g,这东西要切身体会下才会有灵感,对吧,又得花钱了,唉。

Tagged