/**
匿名類目:可以聲明方法和變量,屬性為private(不允許在外部調用,且不能被繼承
*//**
發送數據的委托方,接收數據的時代理發(即代理的反向傳值)
委托方第一步:聲明協議
委托方第二步:聲明代理指針
委托方第三步:操作完成,告訴代理(即調用代理的方法)
代理第一步:遵守協議
代理第二步:成為代理
代理第三步:實現協議方法
*/// %zd %zi 表示NSInteger// %g 表示數字去掉尾零//代碼塊路徑/Users/ms/Library/Developer/Xcode/UserData/CodeSnippets#pragma mark - Xcode快捷鍵Control + A:移動光標到行首
Control + E:移動光標到行末
Control + D:刪除光標右邊的字符
Control + K:刪除本行
// %zd %zi 表示NSInteger// %g 表示數字去掉尾零//代碼塊路徑/Users/ms/Library/Developer/Xcode/UserData/CodeSnippets#pragma mark - Xcode快捷鍵Control + A:移動光標到行首
Control + E:移動光標到行末
Control + D:刪除光標右邊的字符
Control + K:刪除本行
Command + ->:移動到行尾#pragma mark - 本地化
// 找到這個倉庫NSUserDefaults*ud = [NSUserDefaultsstandardUserDefaults];// 存放數據[ud setObject:@"hehe"forKey:@"a"];// 同步[ud synchronize];// 從ud里通過key查詢存儲的對象(可以存放NSString,NSNumber,數組,數組,NSDate,NSData)// 注:ud里不能存放自定義類型(放在容器里也不行)NSString*str = [ud objectForKey:@"a"];
#pragma mark - 通知NSDictionary*dic = [NSDictionarydictionaryWithObjectsAndKeys:@"111", @"aaa",nil];// 通過通知中心,發送一條通知,可以用第二個參數// 工程中所有監控fm90的對象都可以收到者個通知[[NSNotificationCenterdefaultCenter] postNotificationName:@"FM90"object:self.textView.textuserInfo:dic];// 在通知中心注冊了一個觀察者(self),當工程中任何地方發送了FM90這個通知,self都會觸發listenUp這個方法[[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(listenUp:) name:@"FM90"object:nil];// 如果通知中心的觀察者回調里有參數,參數就是NSNotification- (void)listenUp:(NSNotification*)sender
{// 發送廣播時帶的兩個參數//? ? NSLog(@"%@ , %@", sender.name, sender.userInfo);}
- (void)dealloc
{// 當觀察者dealloc的時候,需要移除觀察者身份[[NSNotificationCenterdefaultCenter] removeObserver:selfname:@"FM90"object:nil];
}
#pragma mark - 獲取程序文件相關目錄// 獲取APP Home 目錄NSString* homeDirectory = NSHomeDirectory();// 獲取 文件.app 目錄NSString* appPath = [[NSBundlemainBundle] bundlePath];// 獲取 Documents 目錄NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);NSString* path = [paths objectAtIndex:0];// 獲取 Library 目錄paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask,YES);
path = [paths objectAtIndex:0];// 獲取 Caches 目錄paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask,YES);
path = [paths objectAtIndex:0];// 獲取程序資源路徑//path = [NSBundle mainBundle] pathForResource:(NSString *)ofType:(NSString *)// 加載資源//[[NSBundle mainBundle] loadNibNamed:@"string" owner:nil options:nil]
#pragma mark - 手勢// 找到觸摸事件UITouch *momo = [touches anyObject];// 判斷觸摸的圖片是不是圖片視圖if([momo.viewisKindOfClass:[UIImageViewclass]]) {
[self.viewbringSubviewToFront:momo.view];// 記錄鼠標的原始坐標(移動軌跡原始坐標)_tempPoint = [momo locationInView:self.view];
}// 鼠標點擊次數momo.tapCount/**************六種基本手勢******************/// 點擊手勢(松開鼠標時響應)UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:selfaction:@selector(tapCR:)];// 將手勢添加到view上[view addGestureRecognizer:tapGR];// 拖拽(移動,拖動,move)手勢(這個手勢和清掃手勢沖突)UIPanGestureRecognizer *panGR = [[UIPanGestureRecognizer alloc] initWithTarget:selfaction:@selector(panGR:)];// 縮放手勢UIPinchGestureRecognizer *pinchGR = [[UIPinchGestureRecognizer alloc] initWithTarget:selfaction:@selector(pinchGR:)];// 旋轉手勢UIRotationGestureRecognizer *rotationGR = [[UIRotationGestureRecognizer alloc] initWithTarget:selfaction:@selector(rotationGR:)];// 長按手勢UILongPressGestureRecognizer *longPressGR = [[UILongPressGestureRecognizer alloc] initWithTarget:selfaction:@selector(longPressGR:)];// 輕掃手勢(和移動手勢沖突)UISwipeGestureRecognizer *swipeGR = [[UISwipeGestureRecognizer alloc] initWithTarget:selfaction:@selector(swipeGR:)];// 設置輕掃方向swipeGR.direction= UISwipeGestureRecognizerDirectionUp;// 如果想響應多個方向的清掃需要創建多個清掃手勢的對象UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:selfaction:@selector(swipeGR:)];// 設置輕掃方向swipeLeft.direction= UISwipeGestureRecognizerDirectionLeft;// 輕掃- (void)swipeGR:(UISwipeGestureRecognizer *)swipeGR
{CGRectframe = swipeGR.view.frame;// 判斷輕掃方向if(swipeGR.direction== UISwipeGestureRecognizerDirectionUp) {
frame.size.height+=10;
}// 按位與判斷(用數字1進行按位與運算的結果,可以用按位與來判斷是否相等)if(swipeGR.direction& UISwipeGestureRecognizerDirectionLeft) {
frame.size.height-=10;
}
}// 長按- (void)longPressGR:(UILongPressGestureRecognizer *)longPressGR
{// 判斷手勢狀態if(longPressGR.state== UIGestureRecognizerStateBegan)
}// 旋轉- (void)rotationGR:(UIRotationGestureRecognizer *)rotationGR
{// 讓view旋轉,后面一個參數就是旋轉的角度rotationGR.view.transform= CGAffineTransformRotate(rotationGR.view.transform, rotationGR.rotation);// 每次旋轉以后需要將記錄還原rotationGR.rotation=0;
}// 縮放- (void)pinchGR:(UIPinchGestureRecognizer *)pinchGR
{// 讓view縮放,后面2個參數,一個是x方向縮放的倍數,一個是y方向縮放的倍數pinchGR.view.transform= CGAffineTransformScale(pinchGR.view.transform, pinchGR.scale, pinchGR.scale);// 每次縮放后需要還原倍數的記錄pinchGR.scale=1.0;
}// 移動- (void)panGR:(UIPanGestureRecognizer *)panGR
{// 移動手勢對應的消息(x方向移動多少,y方向移動多少)CGPointpoint = [panGR translationInView:self.view];// 根據軌跡修改手勢對應的viewpanGR.view.center= CGPointMake(panGR.view.center.x+ point.x, panGR.view.center.y+ point.y);// 每次移動以后需要將手勢的軌跡清零[panGR setTranslation:CGPointMake(0,0) inView:self.view];
}// 點擊- (void)tapCR:(UITapGestureRecognizer *)tagRG
{
[self.viewbringSubviewToFront:tagRG.view];
}