iphone开发4 一些小贴士。

1,获取翻转事件,并开启翻转:

只要在viewcontroller的类中加入

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{

//翻转后要执行的代码

return YES;

}

2,-(void)viewWillAppear:(BOOL)animated,- (void)viewDidLoad 的区别。

viewwillappear是每次视图控制器的视图出现前执行的代码。而viewdidload是每次视图控制器载入是执行的代码。

比如说:当a视图控制器的视图第一次出现是两个都要执行,但当a被push后有pop回来时,只有viewwillappear执行。

 

3,如何让视图始终跟着手指移动,并有反弹事件

xsum=photopositon.origin.x+photopositon.size.width/2-touchstart.x;

ysum=photopositon.origin.y+photopositon.size.height/2-touchstart.y;

currentview.center=CGPointMake(xsum+p.x, ysum+p.y);

if (pow(currentview.center.x-160,2.0)>pow(photopositon.size.width/2, 2.0)||pow(currentview.center.y-240,2.0)>pow(photopositon.size.height/2, 2.0)) 

{

[UIView beginAnimations:nil context:NULL];

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

[UIView setAnimationDuration:0.3];

currentview.center=CGPointMake(160, 240);

[UIView commitAnimations];

}

就是让currentview的视图中心始终与手指保持一定的方位。

 

4,控制导航条和toolbar

[self.navigationController   ...]

[self.navigationController.toolbar  ...]

比如说让他们都消失:

[self.navigationController setToolbarItems:NULL animated:YES];

[self.navigationController.toolbar setBarStyle:UIBarStyleBlackTranslucent];

[self.navigationController setToolbarHidden:NO animated:YES];

 

 

5,自定义控件事件:

addTarget:self action:@selector(....) forControlEvents:....

比如获取某个按钮的触摸事件;

[new addTarget:self action:@selector(onChooseItem:) forControlEvents:UIControlEventTouchUpInside]

则当按钮按下时,- (void)onChooseItem:(id) sender 就会被调用。

sender传的就是被按下按钮的指针。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值