RSS
 

研究了一下CATiledLayer的levelsOfDetail和levelsOfDetailBias的含义

02 Sep

levelsOfDetail是指,从UIScrollView的1倍zoomScale开始,能够支持细节刷新的缩小级数。每一级是上一级的1/2,所 以假设levelsOfDetail = n,levelsOfDetailBias不指定的话,CATiledLayer将会在UIScrollView的zoomScale为以下数字时重新 drawLayer
2^-1 -> 2^-2 -> … -> 2^-n
也就是
1/2, 1/4, 1/8, 1/16, … , 1/2^n

在levelsOfDetailBias不指定的情况下,zoomScale大于0.5后就不会再drawLayer,所以若继续放大UIScrollView的话,画面将越来越模糊。

这个时候levelsOfDetailBias就有用了。
levelsOfDetailBias = m表示,将原来的1/2,移到2^m倍的位置。
假设levelsOfDetail = n,levelsOfDetailBias = m的话,会有如下队列:
2^m * 2^-1 -> 2^m * 2^-2 -> … -> 2^m * 2^-n
简化一下即
2^(m – 1) -> 2^(m – 2) -> 2^(m – 3) ->… -> 2^(m – n)

举例,levelsOfDetail = 3,levelsOfDetailBias = 3,则你的UIScrollView将会在以下zoomScale时drawLayer
2^(3 – 1) -> 2^(3 – 2) -> 2^(3 – 3)
即4 -> 2 -> 1

特例是,levelsOfDetailBias > levelsOfDetail时,则每相差2倍就会drawLayer一下。

可以简单理解成:
levelsOfDetail表示一共有多少个drawLayer的位置
levelsOfDetailBias表示比1大的位置里有多少个drawLayer的位置(包括1)

以上若还没看懂的话,以下是图(点开看原始大小)
图中灰色的格子表示跨界的格子,它们本来是同一个格子,被1这条线分割了。

 
No Comments

Posted in Dev

 

iPhone4 or iOS4, Cydia

15 Aug

首先,进入Cydia后,选择用户界面,并Complete Update一下。然后到Sections这个tab,在Edit里,把Theme、Ringtone、Wallpaper之类的都关闭。这样可以大大加快Cydia刷新的速度。

然后,Cydia添加sources,推荐如下:

  • http://www.sinfuliphonerepo.com
  • http://cydia.xsellize.com (or apt.xsellize.com)
  • http://cydia.myrepospace.com/HackStor
  • http://theiphonespotrepo.ne t/apt
  • http://repo.insanelyiph0ne.com (or http://repo.insanelyi.com)
  • http://repo.modyouri.com
  • http://app.weiphone.com/cydia
  • http://c.imodzone.net
  • http://cy.sosiphone.com
  • http://cydia.hackulo.us

最后,推荐一些我装的并测试可用的软件,括号里是安装来源,因为有的软件原版需要付费,想免费使用的话得找其他破解源。

  • Action Menu (from BigBoss) 让选中文字时弹出的菜单有更多的功能,而且会把文字改成图标,更直观易懂
  • AppSync for OS 4.x (from SiNfuL) 越狱后跟iTunes同步必备。
  • Backgrounder (from BigBoss) 让真正的后台跟iOS4的后台共存
  • CyDelete (from BigBoss) 使你能够在桌面删除Cydia装的软件
  • FIT4 (from WeiPhone) 中文输入法,很棒的,我以前做过一个五笔画的键盘,比原版内置的好用多了~如果谁需要的话请留言,我传上来。
  • iFile (from TheiPhoneSpot) 原版不免费。一个超强的文件管理软件,打开其Wifi功能后,就能在浏览器里随意访问和添加修改iPhone内部文件了。
  • Installous 3 (from SiNfuL) 原版已过期,这个是第三方升级版。一个破解软件的App Store,直接在这个软件内浏览并下载即可,还支持在iPhone端安装ipa格式的软件。
  • Landscape Lock Rotation (from insanely) 原版不免费,仅支持OS4,使得OS4的屏幕锁定功能支持横屏
  • LockInfo (from hackstor) 原版不免费。可以在锁屏界面上显示各种信息的软件~曾经买过,但换了手机后貌似还要再买一遍,5.几美元,不高兴买了……
  • KuaiDial (from kuaidial.googlecode.com/svn/deb) 安装后在电话软件里可以拼音首字母搜索联系人,速度极快
  • MobileTerminal iOS4 (from xSellize) 有时候需要在iPhone上输入命令行,用这个……
  • MyWi 4.3.4-8 (from MyRepoSpace) 原版不免费。使你的iPhone变成wifi热点共享3G网络,也就是MIFI功能。
  • PDF Patch  iPhone pdf漏洞补丁,如果不想升级但又想补上这个漏洞的话。
  • PoedCrack GUI (from xSellize) 用它可以破解你购买的正版软件。(I never support that! 本人不支持破解正版软件!)
  • Quick Reply for SMS (from SiNful) 原版不免费。不用进入短信程序就能回复和查看短信的便捷工具
  • Remove Recents (from BigBoss) iOS4底部多任务的图标是不是把不是后台的图标也放进去了?用了这个后,就会只显示当前后台正在运行的软件
  • Rotation Inhibitor (from insanelyi) iOS4自带的屏幕旋转锁定只能是竖屏锁定。用这个SBSettings的插件,横竖屏都能够锁定了。
  • SBSettings (from BigBoss) 从信号栏滑动打开的多功能菜单,可以非常方便地开关各个无线模快和重启手机等众多功能,还能隐藏桌面上一些不用地软件的图标。
  • Signal cracked (从weiphone论坛上下的…) 原版不免费。一个显示手机正在连接的基站以及所有备用连接基站,以及各个基站的信号和位置。
  • SpringFlash (from BigBoss) 通过Activator设置某种启动方式后,可以快捷地打开iPhone4地闪光灯,拿来当电筒用
  • ultrasn0w (from weiphone) iPhone4如果有锁的话,并且如果需要解锁的话,装这个
  • 百度输入法 for OS4.x (from WeiPhone) iOS4上唯一能用的第三方输入法,支持笔画、五笔、拼音、T9键盘等
  • 3G Unrestrictor (from insanelyi) 原版不免费。可以让某些软件把3G网络当Wifi网络来用,这样就能突破一些软件的限制,比如facetime、App Store下软件等。

欢迎指正和推荐更多的信息~

 
 

A simple tutorial of UISearchDisplayerController

25 Feb

I find out that, the API for UISearchDisplayerController in SDK 3.0b is different from 3.0. And there’s no sample code for UISearchDisplayerController anywhere else until now. (Yes, there is one in Apple’s sample code web page, but it uses Interface Builder to realize it. And there is one from the source code of “three20″, but it’s based on SDK 3.0b. )

So I wrote this sample based on “Table Search” sample code.It realizes UISearchDisplayerController programmatically without Interface Builder. It supports landscape screen and search scopes, and integrate one UITabBarController with two UITableViewControllers.

Here is the tutorial .

@interface

  1. Declare an instance of UISearchDisplayerController and set as property.
  2. Prepare two arrays to hold original data and filtered data.

@implementation

  1. Set up viewDidLoadmethod
    1. Create an UISearchBar.
    2. Initialize the UISearchDisplayController based on the UISearchBar:
      1
      
      [[UISearchDisplayController alloc] initWithSearchBar:mySearchBar contentsController:self];
    3. Set the UISearchDisplayController instance:
      1
      2
      3
      
      [self setSearchDisplayController:searchDisplayController];
      [searchDisplayController setDelegate:self];
      [searchDisplayController setSearchResultsDataSource:self];
  2. Set up UISearchDisplayController delegate methods:
      1
      2
      3
      
      - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
      - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption
      - (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller

      Be careful, we need to set the delegate for self.searchDisplayController.searchResultsTableView each time we begin to search. Because the instance of searchResultsTableView is allocated and released automatically.

  3. Set up UITableView data source and delegate methods, we distinguish filtered or not filtered table by
      1
      
      if (tableView == self.searchDisplayController.searchResultsTableView)
  4. Remember to return YES in shouldAutorotateToInterfaceOrientation to support landscape screen.


Some details need to be cared:

  1. self.searchDisplayController.searchResultsTableView is created and release automatically, so its delegate should be setted each time it’s created.
  2. Every time we turn to a landscape UITableViewController, the UISearchBar in the tableHeaderView has only a width of 320 even we have already setted sizeToFit. It’s may be caused by UITabBarController, I don’t know. So I set the frame of tableHeaderView based on the screen orientation manually in the viewDidLoad method.

Sample Code(.zip)

 
No Comments

Posted in Dev

 

base64 encoder decoder for objective-c (iPhone or Mac)

24 Feb

I use base64 encoder and decoder to put binary data of images into xml data, then transfer the non-text data as text data between server and client.

Here’s an example in my iPhone project.

base64.zip

Download these two files and import them in your project and include the head file in your class file.

(Thanks to Jonathan Wight, who wrote it on Mar 18, 2003)

There are four methods in the base64 head file.

extern size_t EstimateBas64EncodedDataSize(size_t inDataSize);
extern size_t EstimateBas64DecodedDataSize(size_t inDataSize);
extern bool Base64EncodeData(const void *inInputData, size_t inInputDataSize, char *outOutputData, size_t *ioOutputDataSize, BOOL wrapped);
extern bool Base64DecodeData(const void *inInputData, size_t inInputDataSize, void *ioOutputData, size_t *ioOutputDataSize)

Here’s the usage of decoding a string data.

NSString *stringValue = /*the UTF8 string parsed from xml data*/
Byte inputData[[stringValue lengthOfBytesUsingEncoding:NSUTF8StringEncoding]];//prepare a Byte[]
[[stringValue dataUsingEncoding:NSUTF8StringEncoding] getBytes:inputData];//get the pointer of the data
size_t inputDataSize = (size_t)[stringValue length];
size_t outputDataSize = EstimateBas64DecodedDataSize(inputDataSize);//calculate the decoded data size
Byte outputData[outputDataSize];//prepare a Byte[] for the decoded data
Base64DecodeData(inputData, inputDataSize, outputData, &outputDataSize);//decode the data
NSData *theData = [[NSData alloc] initWithBytes:outputData length:outputDataSize];//create a NSData object from the decoded data

 
7 Comments

Posted in Dev

 

How to uninstall Xcode and iPhone SDK

24 Feb

Open Terminal, type

sudo /Developer/Library/uninstall-devtools --mode=all
 
Comments Off

Posted in Dev