1 用CGRectContainsPoint判断点是否在CGRect里。
2 如果父视图为ParentView包含一个Button,如果再ParentView上添加子视图ChildView,且ChildView盖住了Button,那么Button就得到不响应了,为了让Button响应,可以设置ChildView的userInteractionEnabled = NO;
3
算术函数
函数名 | 说明 |
---|---|
int rand() |
随机数生成。 (例) srand(time(nil)); //随机数初期化 int val = rand()%50; //0~49之间的随机数 |
int abs(int a) |
整数的绝对值 (例)int val = abs(-8); →8 ※浮点数的时候用fabs。 |
double fabs(double a) |
浮点数的绝对值 (例)double val = fabs(-12.345); →12.345 ※整数的时候用abs。 |
double floor(double a) |
返回浮点数整数部分(舍弃小数点) (例)double val = floor(12.345); →12.000 |
double ceil(double a); |
返回浮点数整数部分(舍弃小数点部分,往个位数进1) (例)double val = ceil(12.345); →13.000 |
double pow(double a, double b) |
a的b次方 (例)double val = pow(2, 3); →8 |
double sqrt(double a) |
a的平方根 (例)double val = sqrt(2); →1.41421356 |
三角函数
函数名 | 说明 |
---|---|
double cos(double a) | 余弦函数 (a:弧度) |
double sin(double a) | 正弦函数 (a:弧度) |
double tan(double a) | 正切函数 (a:弧度) |
double asin(double a) | 反正弦值 (a:弧度) |
double acos(double a) | 反余弦函数(a:弧度) |
double atan(double a) | 反正切函数 |
double atan2(double a, double b) | 返回给定的 a 及 b 坐标值的反正切值 |
指数函数
函数名 | 说明 |
---|---|
double log(double a) | 以e 为底的对数值 |
double log10(double a) | 对数函数log |
常数
常数名 | 说明 |
---|---|
M_PI | 圆周率(=π) |
M_PI_2 | 圆周率的1/2(=π/2) |
M_PI_4 | 圆周率的1/4(=π/4) |
M_1_PI | =1/π |
M_2_PI | =2/π |
M_E | =e |
M_LOG2E | log_2(e) |
M_LOG10E | log_10(e) |
4 设置或使用CALayer,需要导入QuartzCore.framework库.
5 代码添加UIButton,必须设置其frame,否则不显示
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(0, 0, 65, 25); //无此行,则,不显示在UIView上
[button setTitle:@"提交" forState:UIControlStateNormal];
[button addTarget:self action:@selector(submit:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
6 修改useragent.
-(void)initUseragent
{
// NSDictionary *dictionnary = [[NSDictionary alloc] initWithObjectsAndKeys:@"5cc7fea9c70d4e230fcb80ad0b872a32", @"UserAgent", nil];
// [[NSUserDefaults standardUserDefaults] registerDefaults:dictionnary];
// [dictionnary release];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setValue:@"5cc7fea9c70d4e230fcb80ad0b872a32" forHTTPHeaderField:@"user-agent"];
[request setURL:[NSURL URLWithString:@"http://api.shupeng.com/board"]];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
if(data)
{
id t = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
NSLog(@"%@", t);
}
}
7 UITextField 只出现光标,不弹出键盘.
自定义一个view,view上面什么都不加.bounds可以设置为CGRectZero..把这个view设置为textfield的input view.
UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
_display.inputView = view;
[view release];
UITextFieldDelegate:
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
return NO;
}
此方法,既不出现光标,也不出现键盘.