1. 擷取當天日期
NSDate *today;
today = [NSDate date];
2.[[UIDevice currentDevice] orientation] 通過這個擷取裝置狀態是有以下七個狀態:
UIDeviceOrientationUnknown
UIDeviceOrientationPortrait //Device oriented vertically, home button one the button
UIDeviceOrientationPortraitUpsideDown //Device oriented vertically, home button one the top
UIDeviceOrientationLandscapeLeft //Device oriented horizontally,home button on the right
UIDeviceOrientationLandscapeRight //Device oriented horizontally, home button on the left
UIDeviceOrientationFaceUp //Device oriented flat, face up
UIDeviceOrientationFaceDown //Device oriented flat, face down
在有第一個和最後兩個狀態的情況下,如果是在狀態發生變化的時候去做一些操作,那麼是沒問題的,因為操作的時候只捕獲四個旋轉狀態即可。但是如果要根據在做操作的時候根據狀態去做某些事情就會有問題,因為非常有可能取到那三個非旋轉狀態。解決方案:記住上一個旋轉狀態,當發現擷取的狀態不是四個旋轉狀態的時候,使用上一個正常旋轉狀態。
- (void)applicationDidFinishLaunching:(UIApplication *)application { [window addSubview:crateViewController.view]; [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];}
- (void)orientationChanged:(NSNotification *)notification{ UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation]; if (UIDeviceOrientationIsPortrait(orientation) || UIDeviceOrientationIsLandscape(orientation)) { if (!currentOrientation) { currentOrientation = orientation; [self prepareScreen]; } currentOrientation = orientation; } [[UIApplication sharedApplication] setStatusBarOrientation:currentOrientation animated:YES];}
3.UIButton 能吃掉所有的Touches事件,暫時還沒有找到穿透的方法。
說明:在UIView中放置一個UIButton,這個UIButton的大小和UIView的大小和位置完全一致,這樣的話UIView本身擁有的touchesBegan: touchesMoved:touchesEnded:等等事件全部都不能捕獲到了。如果有相應的業務需求怎麼辦呢,建議用UIImageView, 通過touchesBegan和TouchesEnden事件來改變圖片的資源,這樣的話,也能達到button的點擊效果了。