不了解Matrix的同学看这里:
弄明白matrix那几个方法的使用了,比如preTranslate, setTranslate, postTranslate这些。以前对它们都是一知半解,以为这几个方法没什么区别,其实还是有很大不同的,最紧要是这几个方法的调用顺序对坐标变换的影响。抽象的说pre方法是向前"生长", post方法是向后"生长",具体拿个例子来说,比如一个matrix调用了下列一系列的方法:
matrix.preScale(0.5f, 1);
matrix.preTranslate(10, 0);
matrix.postScale(0.7f, 1);
matrix.postTranslate(15, 0);
则坐标变换经过的4个变换过程依次是:
translate(10, 0) -> scale(0.5f, 1) -> scale(0.7f, 1) -> translate(15, 0)
所以对matrix方法的调用顺序是很重要的,不同的顺序往往会产生不同的变换效果。pre方法的调用顺序和post方法的互不影响,即以下的方法调用和前者在真实坐标变换顺序里是一致的
matrix.postScale(0.7f, 1);
matrix.preScale(0.5f, 1);
matrix.preTranslate(10, 0);
matrix.postTranslate(15, 0);
而matrix的set方法则会对先前的pre和post操作进行刷除,而后再设置它的值,比如下列的方法调用:
matrix.preScale(0.5f, 1);
matrix.postTranslate(10, 0);
matrix.setScale(1, 0.6f);
matrix.postScale(0.7f, 1);
matrix.preTranslate(15, 0);
其坐标变换顺序是:translate(15, 0) -> scale(1, 0.6f) -> scale(0.7f, 1).
这是因为setScale重新设置了矩阵的值,之前的两个变换是无效的了,所以最终的显示效果只有三个变换效果。
Canvas里scale, translate, rotate, concat方法都是pre方法,如果要进行更多的变换可以先从canvas获得matrix, 变换后再设置回canvas.
假如出现模拟器中的sdcard只有可读权限时,如以下信息:
# pwd
pwd
/mnt/sdcard
# mkdir test
mkdir test
mkdir failed for test, Read-only file system
或者编译代码时出现:
/System.err( 1093): java.io.FileNotFoundException: /mnt/sdcard/DownloadApk/XXX.apk (Permission denied)
/System.err( 1093): at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
/System.err( 1093): at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:232)
/System.err( 1093): at java.io.FileOutputStream.<init>(FileOutputStream.java:94)
/System.err( 1093): at java.io.FileOutputStream.<init>(FileOutputStream.java:66)
则可能是模拟器没有开通sdcard support的功能。
只需进入AVD Manager界面,并选中将用的AVD,编辑其属性,即在Hardware选项中new一个“SD Card support”选项即可。
并adb shell进入命令行
修改sdcard目录下的读写权限:
chmod 075 /mnt/sdcard (不要直接用777,不能成功执行的)
From: http://tsyouaschen.iteye.com/blog/972683
- (void)configurePickersAndActionSheets { CGRect pickerFrame; if ((self.interfaceOrientation == UIInterfaceOrientationPortrait) || (self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)) { pickerFrame = CGRectMake(0, 180, 0, 0); } else { pickerFrame = CGRectMake(0,180,480,200); } self.areaActionSheet = [[[UIActionSheet alloc] initWithTitle:@"Area" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Use",NULL] autorelease]; self.areaPicker = [[[UIPickerView alloc] initWithFrame:pickerFrame] autorelease]; self.areaPicker.delegate = self; self.areaPicker.showsSelectionIndicator = YES; [self.areaActionSheet addSubview:areaPicker]; }
上面的代码就是横屏和纵屏的大小设置
if ((self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight)) { [actionSheet setBounds:CGRectMake(0, 0, 480, 480)]; } else { [actionSheet setBounds:CGRectMake(0, 0, 320, 618)]; }此处用来设置actionsheet的大小具体的添加PickerView如下:UIActionSheet * menu = [ [ UIActionSheet alloc ] initWithTitle : [ currentData objectAtIndex : 0 ]delegate : self cancelButtonTitle : @ "Done" destructiveButtonTitle : @ "Cancel" otherButtonTitles : nil ] ;
UIPickerView * pickerView = [ [ UIPickerView alloc] initWithFrame: CGRectMake( 0,40,480,200) ] ;
pickerView.delegate = self; pickerView.showsSelectionIndicator = YES ;
[ menu addSubview: pickerView] ; [ menu showInView: self.view] ; [ menu setBounds: CGRectMake( 0,0,480, 320) ] ;
[ pickerView release] ; [ menu release] ;
OK这个就完成了ActionSheet的操作,可能你还会有一个问题就是在UIPickerView如何设置显示下拉框的
字体大小,即改变显示数组中的字体大小:
需要重写实现如下方法
- (UIView *)pickerView:(UIPickerView *)pickerView
viewForRow:(NSInteger )row
forComponent:(NSInteger )component
reusingView:(UIView *)view {
UILabel *pickerLabel = (UILabel *)view ;
if ((pickerLabel == nil ) || ([pickerView class ] != [UILabel class ])) {
CGRect frame = CGRectMake (0 , 0 , 270 , 32 );
pickerLabel = [[UILabel alloc ] initWithFrame :frame];
pickerLabel. textAlignment = UITextAlignmentLeft;
pickerLabel. backgroundColor = [ UIColor clearColor ];
pickerLabel.font = [UIFont boldSystemFontOfSize :18 ];
if (component == kStateComponent ) {
pickerLabel. textAlignment = UITextAlignmentCenter;
pickerLabel.text = [self .states objectAtIndex :row];
}
else if (component == kZipComponent ){
pickerLabel. textAlignment = UITextAlignmentLeft;
pickerLabel.text = [self .zips objectAtIndex :row];
}
pickerLabel.textColor = [UIColor blackColor ];
return pickerLabel;
}
return 0 ;
}