/**
匿名類目:可以聲明方法和變量魄宏,屬性為private(不允許在外部調(diào)用巴刻,且不能被繼承
*//**
發(fā)送數(shù)據(jù)的委托方派桩,接收數(shù)據(jù)的時(shí)代理發(fā)(即代理的反向傳值)
委托方第一步:聲明協(xié)議
委托方第二步:聲明代理指針
委托方第三步:操作完成伶授,告訴代理(即調(diào)用代理的方法)
代理第一步:遵守協(xié)議
代理第二步:成為代理
代理第三步:實(shí)現(xiàn)協(xié)議方法
*/// %zd %zi 表示NSInteger// %g 表示數(shù)字去掉尾零//代碼塊路徑/Users/ms/Library/Developer/Xcode/UserData/CodeSnippets#pragma mark - Xcode快捷鍵Control + A:移動(dòng)光標(biāo)到行首
Control + E:移動(dòng)光標(biāo)到行末
Control + D:刪除光標(biāo)右邊的字符
Control + K:刪除本行
// %zd %zi 表示NSInteger// %g 表示數(shù)字去掉尾零//代碼塊路徑/Users/ms/Library/Developer/Xcode/UserData/CodeSnippets#pragma mark - Xcode快捷鍵Control + A:移動(dòng)光標(biāo)到行首
Control + E:移動(dòng)光標(biāo)到行末
Control + D:刪除光標(biāo)右邊的字符
Control + K:刪除本行
Command + ->:移動(dòng)到行尾#pragma mark - 本地化
// 找到這個(gè)倉(cāng)庫(kù)NSUserDefaults*ud = [NSUserDefaultsstandardUserDefaults];// 存放數(shù)據(jù)[ud setObject:@"hehe"forKey:@"a"];// 同步[ud synchronize];// 從ud里通過(guò)key查詢存儲(chǔ)的對(duì)象(可以存放NSString,NSNumber登钥,數(shù)組,數(shù)組娶靡,NSDate怔鳖,NSData)// 注:ud里不能存放自定義類型(放在容器里也不行)NSString*str = [ud objectForKey:@"a"];
#pragma mark - 通知NSDictionary*dic = [NSDictionarydictionaryWithObjectsAndKeys:@"111", @"aaa",nil];// 通過(guò)通知中心,發(fā)送一條通知固蛾,可以用第二個(gè)參數(shù)// 工程中所有監(jiān)控fm90的對(duì)象都可以收到者個(gè)通知[[NSNotificationCenterdefaultCenter] postNotificationName:@"FM90"object:self.textView.textuserInfo:dic];// 在通知中心注冊(cè)了一個(gè)觀察者(self)结执,當(dāng)工程中任何地方發(fā)送了FM90這個(gè)通知,self都會(huì)觸發(fā)listenUp這個(gè)方法[[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(listenUp:) name:@"FM90"object:nil];// 如果通知中心的觀察者回調(diào)里有參數(shù)艾凯,參數(shù)就是NSNotification- (void)listenUp:(NSNotification*)sender
{// 發(fā)送廣播時(shí)帶的兩個(gè)參數(shù)//? ? NSLog(@"%@ , %@", sender.name, sender.userInfo);}
- (void)dealloc
{// 當(dāng)觀察者dealloc的時(shí)候献幔,需要移除觀察者身份[[NSNotificationCenterdefaultCenter] removeObserver:selfname:@"FM90"object:nil];
}
#pragma mark - 獲取程序文件相關(guān)目錄// 獲取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 - 手勢(shì)// 找到觸摸事件UITouch *momo = [touches anyObject];// 判斷觸摸的圖片是不是圖片視圖if([momo.viewisKindOfClass:[UIImageViewclass]]) {
[self.viewbringSubviewToFront:momo.view];// 記錄鼠標(biāo)的原始坐標(biāo)(移動(dòng)軌跡原始坐標(biāo))_tempPoint = [momo locationInView:self.view];
}// 鼠標(biāo)點(diǎn)擊次數(shù)momo.tapCount/**************六種基本手勢(shì)******************/// 點(diǎn)擊手勢(shì)(松開鼠標(biāo)時(shí)響應(yīng))UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:selfaction:@selector(tapCR:)];// 將手勢(shì)添加到view上[view addGestureRecognizer:tapGR];// 拖拽(移動(dòng),拖動(dòng)趾诗,move)手勢(shì)(這個(gè)手勢(shì)和清掃手勢(shì)沖突)UIPanGestureRecognizer *panGR = [[UIPanGestureRecognizer alloc] initWithTarget:selfaction:@selector(panGR:)];// 縮放手勢(shì)UIPinchGestureRecognizer *pinchGR = [[UIPinchGestureRecognizer alloc] initWithTarget:selfaction:@selector(pinchGR:)];// 旋轉(zhuǎn)手勢(shì)UIRotationGestureRecognizer *rotationGR = [[UIRotationGestureRecognizer alloc] initWithTarget:selfaction:@selector(rotationGR:)];// 長(zhǎng)按手勢(shì)UILongPressGestureRecognizer *longPressGR = [[UILongPressGestureRecognizer alloc] initWithTarget:selfaction:@selector(longPressGR:)];// 輕掃手勢(shì)(和移動(dòng)手勢(shì)沖突)UISwipeGestureRecognizer *swipeGR = [[UISwipeGestureRecognizer alloc] initWithTarget:selfaction:@selector(swipeGR:)];// 設(shè)置輕掃方向swipeGR.direction= UISwipeGestureRecognizerDirectionUp;// 如果想響應(yīng)多個(gè)方向的清掃需要?jiǎng)?chuàng)建多個(gè)清掃手勢(shì)的對(duì)象UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:selfaction:@selector(swipeGR:)];// 設(shè)置輕掃方向swipeLeft.direction= UISwipeGestureRecognizerDirectionLeft;// 輕掃- (void)swipeGR:(UISwipeGestureRecognizer *)swipeGR
{CGRectframe = swipeGR.view.frame;// 判斷輕掃方向if(swipeGR.direction== UISwipeGestureRecognizerDirectionUp) {
frame.size.height+=10;
}// 按位與判斷(用數(shù)字1進(jìn)行按位與運(yùn)算的結(jié)果蜡感,可以用按位與來(lái)判斷是否相等)if(swipeGR.direction& UISwipeGestureRecognizerDirectionLeft) {
frame.size.height-=10;
}
}// 長(zhǎng)按- (void)longPressGR:(UILongPressGestureRecognizer *)longPressGR
{// 判斷手勢(shì)狀態(tài)if(longPressGR.state== UIGestureRecognizerStateBegan)
}// 旋轉(zhuǎn)- (void)rotationGR:(UIRotationGestureRecognizer *)rotationGR
{// 讓view旋轉(zhuǎn),后面一個(gè)參數(shù)就是旋轉(zhuǎn)的角度rotationGR.view.transform= CGAffineTransformRotate(rotationGR.view.transform, rotationGR.rotation);// 每次旋轉(zhuǎn)以后需要將記錄還原rotationGR.rotation=0;
}// 縮放- (void)pinchGR:(UIPinchGestureRecognizer *)pinchGR
{// 讓view縮放恃泪,后面2個(gè)參數(shù)郑兴,一個(gè)是x方向縮放的倍數(shù),一個(gè)是y方向縮放的倍數(shù)pinchGR.view.transform= CGAffineTransformScale(pinchGR.view.transform, pinchGR.scale, pinchGR.scale);// 每次縮放后需要還原倍數(shù)的記錄pinchGR.scale=1.0;
}// 移動(dòng)- (void)panGR:(UIPanGestureRecognizer *)panGR
{// 移動(dòng)手勢(shì)對(duì)應(yīng)的消息(x方向移動(dòng)多少贝乎,y方向移動(dòng)多少)CGPointpoint = [panGR translationInView:self.view];// 根據(jù)軌跡修改手勢(shì)對(duì)應(yīng)的viewpanGR.view.center= CGPointMake(panGR.view.center.x+ point.x, panGR.view.center.y+ point.y);// 每次移動(dòng)以后需要將手勢(shì)的軌跡清零[panGR setTranslation:CGPointMake(0,0) inView:self.view];
}// 點(diǎn)擊- (void)tapCR:(UITapGestureRecognizer *)tagRG
{
[self.viewbringSubviewToFront:tagRG.view];
}