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传的就是被按下按钮的指针。