iOS的開發(fā)小冷易忘知識點總結(jié)

首先感謝小易童鞋,這里自己也整理下這些容易忘記的代碼

設(shè)置導航欄的背景顏色用barTintColor

self.navigationBar.barTintColor = [UIColor colorWithRed:3/255.0f green:101/255.0f blue:100/255.0f alpha:1.0f] ;

獲取的.plist文件:

//1.從本地文件中讀取數(shù)據(jù)(在實際項目開發(fā)中在這寫網(wǎng)絡(luò)請求) // 獲取文件本地的路徑 NSString *filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"json"]; // 把本地數(shù)據(jù)讀取出來,不需要任何轉(zhuǎn)換,就是二進制數(shù)據(jù) NSData *jsonData = [[NSData alloc] initWithContentsOfFile:filePath];

NSString的字符串轉(zhuǎn)換成的NSData類型的數(shù)據(jù):

// NSString字符串轉(zhuǎn)換成NSData類型的數(shù)據(jù) NSData *jsondata = [result dataUsingEncoding:NSUTF8StringEncoding] ; NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsondata options:NSJSONReadingMutableContainers error:nil] ;

獲取文本的高度:

// Label中文字的大小默認是18 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
WeiBoModel *weiboModel = _dataList[indexPath.row] ; NSString *textString = weiboModel.text ; CGSize size = [textString sizeWithFont:[UIFont systemFontOfSize:18] constrainedToSize:CGSizeMake(kScreenWidth, 1000)] ; return size.height +20;
}

設(shè)置圖片拉伸:

// 設(shè)置圖片拉伸 UIImage *bgImage = [UIImage imageNamed:@"userinfo_shadow_pic.png"];
_bgImageView.image = [bgImage stretchableImageWithLeftCapWidth:15 topCapHeight:15];

設(shè)置圖片圓角:

// 設(shè)置圓角 _userImageView.layer.cornerRadius = 25;
_userImageView.layer.masksToBounds = YES;

設(shè)置點擊細胞然后不留下點擊的痕跡:

// 設(shè)置沒有痕跡 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES] ;
}

設(shè)置按鈕中圖片和文本的位置

button.imageEdgeInsets = UIEdgeInsetsMake(0, -100, 0, 0) ;
button.titleEdgeInsets = UIEdgeInsetsMake(0, -100, 0, 0) ;

延遲調(diào)用

// 延遲兩秒鐘調(diào)用yanchiAction方法 [self performSelector:@selector(yanchiAction) withObject:nil afterDelay:0.2] ;

刷新UICollectionView視圖

[cell setNeedsLayout] ;

設(shè)置內(nèi)填充

self.contentInset = UIEdgeInsetsMake(0, 0, 0, 0) ;

設(shè)置tabBarView的標簽欄沒有內(nèi)填充效果

self.automaticallyAdjustsScrollViewInsets = NO ;

判斷字符串是否的開頭

if([context hasPrefix:@"@"]) ;

請求數(shù)據(jù)從控制臺打印成數(shù)據(jù)類型的數(shù)據(jù)方便進行JSON解析

po operation.responseString

禁止滑動視圖滑動

scrollView.scrollEnabled = NO;

設(shè)置超出父視圖部分不減切

_scrollView.clipsToBounds = NO ;

取消的UIScrollView的彈性效果

scrollView.bounces = NO;

滾動型禁止滑動

scrollView.scrollEnabled = YES;

判斷點擊的是哪個視圖,返回值是個視圖

tap.view.tap

這是的tableView沒有默認的分割線

self.separatorStyle = NO ;

子視圖超過父視圖點擊沒反應(yīng)

(注意:如果父視圖是UIScrollView中,需要設(shè)置self.bgScrollView.clipsToBounds = NO ;,因為UIScrollView中默認會進行裁剪,會導致超出的部分沒有了)

  • (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { CGPoint hitPoint = [self.cardView.dayRateHelp convertPoint:point fromView:self]; if ([self.cardView.dayRateHelp pointInside:hitPoint withEvent:event]) return self.cardView.dayRateHelp; return [super hitTest:point withEvent:event];
    }

用KVC修改UIPageControl的選中圖片和默認圖片(系統(tǒng)默認是不允許修改的)

[self.pageControl setValue:currentImage forKey:@"_currentPageImage"];
[self.pageControl setValue:pageImage forKey:@"_pageImage"];

清除文本視圖按鈕

textField.clearButtonMode = UITextFieldViewModeWhileEditing;

點擊單元格不留下點擊的痕跡

  • (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
    [tableView deselectRowAtIndexPath:indexPath animated:YES] ;
    }

設(shè)置單元格選中的樣式(無樣式)

cell.selectionStyle = UITableViewCellSelectionStyleNone ;

設(shè)置標簽欄的選種文字和圖片顏色

self.tabBar.tintColor = [UIColor redColor] ;

故事版創(chuàng)建靜態(tài)單元格,注意創(chuàng)建的UITableViewControl文件的.m文件中有部分自動創(chuàng)建的代碼時需要刪除的,如果是集成于baseTableViewControl也要刪除代碼

// 獲取故事版 UIStoryboard *board = [UIStoryboard storyboardWithName:@"Main" bundle:nil];// 獲取視圖 MyTableViewController *myView = [board instantiateViewControllerWithIdentifier:@"MyID"] ;

判斷一個字典里是否有某個關(guān)鍵

if([[dic allKeys]containsObject:@"key"])

隨機數(shù)

long price = arc4random()%10*1000 ;

刷新視圖

[label setNeedsDisplay] ;

延遲幾秒鐘執(zhí)行

[self performSelector:@selector(delayMethod) withObject:nil afterDelay:1.0f];

去掉細胞的分割線(如果是用廈門國際銀行做的,右邊也有這個屬性,設(shè)置為無即可)

tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

取消單元格選中效果

tableView.selectionStyle = UITableViewCellSelectionStyleNone;

  • 數(shù)據(jù)發(fā)生改變后一定要重新刷新數(shù)據(jù)
  • (void)viewWillAppear:(BOOL)animated{

[super viewWillAppear:animated]; /** * clearsSelectionOnViewWillAppear * 這個是它的一個屬性,默認是yes 返回列表頁面的時候,默認取消這行的選中狀態(tài),可是我們已經(jīng)把這條數(shù)據(jù)刪除的話,會出問題 * 如果你點擊了一行cell,進入下一個頁面,在這個頁面中,我們把本該屬于這行cell的數(shù)據(jù)給刪了 * 如果 self.clearsSelectionOnViewWillAppear = yes,返回前一頁時,會刷新這一行cell,執(zhí)行cellForRow方法,結(jié)果數(shù)據(jù)卻沒了,就崩潰了 * 如果 self.clearsSelectionOnViewWillAppear = no,不會刷新這一行cell,就沒事兒了 */ self.clearsSelectionOnViewWillAppear =NO;
[self.tableView reloadData];---->并不一定要放在這里,看取得數(shù)據(jù)在什么位置,刷新數(shù)據(jù)在什么位置
}

awakeFromNib(故事板)和viewDidLoad中的區(qū)別

awakeFromNib

當.nib文件被加載的時候,會發(fā)送一個awakeFromNib的消息到.nib文件中的每個對象,每個對象都可以定義自己的 awakeFromNib函數(shù)來響應(yīng)這個消息,執(zhí)行一些必要的操作。也就是說通過nib文件創(chuàng)建view對象是執(zhí)行awakeFromNib 。

viewDidLoad中

當view對象被加載到內(nèi)存是就會執(zhí)行viewDidLoad,所以不管通過nib文件還是代碼的方式創(chuàng)建對象都會執(zhí)行viewDidLoad。awakeFromNib和viewDidLoad的區(qū)別

將漢字轉(zhuǎn)換為不帶音調(diào)的拼音

  • (NSString )transformMandarinToLatin:(NSString )string
    {
    NSMutableString preString = [string mutableCopy]; /轉(zhuǎn)換成成帶音 調(diào)的拼音
    / CFStringTransform((CFMutableStringRef)preString, NULL, kCFStringTransformMandarinLatin, NO); /
    去掉音調(diào)*/ CFStringTransform((CFMutableStringRef)preString, NULL, kCFStringTransformStripDiacritics, NO); return preString;
    }

圖片適應(yīng)問題(超出部分裁剪)

有兩個觀點:視圖1,視圖2

視圖2添加視圖1到中,如果視圖2大于廠景,或者視圖2的坐標不全在廠景的范圍內(nèi),視圖2是蓋著廠景的,意思就是超出的部份也會畫出來

的UIView有一個屬性,clipsTobounds默認情況下是NO。

如果,我們想要視圖2把超出的那部份隱藏起來的話
,就得改變它的父視圖也就廠景的clipsTobounds屬性值。

view1.clipsTobounds = YES;

第三方FMDB數(shù)據(jù)庫操作問題

Unknown error finalizing or resetting statement (5: database is locked)

在使用FMDB時有時候一不小心沒寫好代碼就會這樣子啦,為什么呢,其實呢,應(yīng)該是在前面代碼中有調(diào)用數(shù)據(jù)庫而且并沒有調(diào)用[DB關(guān)閉]就直接跳出結(jié)果來了,所以在前面的數(shù)據(jù)庫操作中先運行[DB關(guān)閉]再返回數(shù)據(jù)即可;

通過注冊鍵盤顯示的消息

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShown:)
name:UIKeyboardWillShowNotification object:nil];

  • (void)keyboardWillShown:(NSNotification *)aNotification{// 鍵盤信息字典NSDictionary *info = [aNotification userInfo];

}

改變導航欄中間標題顏色

UIColor * color = [UIColor whiteColor]; NSDictionary * dict = [NSDictionary dictionaryWithObject: colorforKey:NSForegroundColorAttributeName]; self.navigationController.navigationBar.titleTextAttributes = dict;

UIWebView中要實現(xiàn)橫向滑動,跟一個UIWebView的增高沒有關(guān)系,你需要設(shè)定一個UIWebView的屬性滾動視圖的contentsize.width大于UIWebView中的frame.size.width。

如何監(jiān)測系統(tǒng)鍵盤的彈出(有第三方框架很方便)

通過注冊鍵盤顯示的消息

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShown:)

name:UIKeyboardWillShowNotification object:nil];

  • (void)keyboardWillShown:(NSNotification)aNotification{ // 鍵盤信息字典 NSDictionary info = [aNotification userInfo];
    }

改變狀態(tài)欄顏色

在Info.plist中添加

UIViewControllerBasedStatusBarAppearance,設(shè)置值為NO

然后再didFinishLaunchingWithOptions的AppDelegate中,添加這些代碼:

[應(yīng)用setStatusBarHidden:NO]; [應(yīng)用setStatusBarStyle:UIStatusBarStyleLightContent];

路徑截取字符串的一些處理

// 從路徑中獲得完整的文件名(帶后綴)

exestr = [filePath lastPathComponent];

// 獲得文件名(不帶后綴)

exestr = [exestr stringByDeletingPathExtension];

// 獲得文件的擴展類型(不帶'.')

exestr = [filePath pathExtension];

第三方庫不支持64位造成編譯錯誤

。Xcode中升級到5.1,蘋果默認讓所有的應(yīng)用程序都通過64位編譯器編譯通過下面的方式可以關(guān)閉:選中Targets->構(gòu)建設(shè)置 - >架構(gòu)雙擊架構(gòu),選擇其他,刪除$(ARCH_STANDARD)(點' - '),然后增加的ARMv7和armv7s(點'+')。清理一下再編譯就行了。

移動導航欄的方法:

import <QuartzCore/QuartzCore.h>

define kNavBarDefaultPosition CGPointMake(160, 22)

if (contentOffsetY > _scrollViewContentOffsetYThreshold) {

layer.position = CGPointMake(layer.position.x,

  • MIN((contentOffsetY - _scrollViewContentOffsetYThreshold), 48.0));

}

else

{

layer.position = kNavBarDefaultPosition;

}

的CGRect的一些相關(guān)方法:

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(100, 120, 120, 120)];

// 獲取矩形左邊緣的x坐標

NSLog(@"MinX = %f",CGRectGetMinX(view.frame));

// 獲取矩形頂部的y坐標

NSLog(@"MinY = %f",CGRectGetMinY(view.frame));

// 獲取矩形中心點的坐標

NSLog(@"MidX = %f",CGRectGetMidX(view.frame));

NSLog(@"MidY = %f",CGRectGetMidY(view.frame));

// 獲取矩形右邊緣的x坐標

NSLog(@"MaxX = %f",CGRectGetMaxX(view.frame));

// 獲取矩形底部的y坐標

NSLog(@"MaxY = %f",CGRectGetMaxY(view.frame));

// 返回手勢在一個UIView上的觸摸點坐標

  • (CGPoint)locationInView:(UIView *)view:

// 判斷矩形是否包含了一個點

NSLog(@"isRectContainPoint = %d",CGRectContainsPoint(view.frame, CGPointMake(160, 180)));

CGRectInset CGRect CGRectInset (

CGRect rect,

CGFloat dx,

CGFloat dy

);

該結(jié)構(gòu)體的應(yīng)用是以原rect為中心,再參考dx,dy,進行縮放或者放大。

CGRect r1 = CGRectMake(100, 100, 50, 50);

CGRect r3 = CGRectInset(r1, 10, 8);//結(jié)果應(yīng)為:110,108,30,34 具體小多少都是要參照dx和dy來判定的。

CGRectOffset CGRect CGRectOffset(

CGRect rect,

CGFloat dx,

CGFloat dy

); 相對于源矩形原點rect(左上角的點)沿x軸和y軸偏移, 再rect基礎(chǔ)上沿x軸和y軸偏移

float offset = 125.0;

CGRect r1 = CGRectMake(100, 100, 5, 5);

CGRect r2 = CGRectOffset(r1, offset, offset);

結(jié)果:

{{225, 225}, {5, 5}}

// 將像素point由point所在視圖轉(zhuǎn)換到目標視圖view中,返回在目標視圖view中的像素值

  • (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view;

// 將像素point從view中轉(zhuǎn)換到當前視圖中,返回在當前視圖中的像素值

  • (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view;

// 將rect由rect所在視圖轉(zhuǎn)換到目標視圖view中,返回在目標視圖view中的rect

  • (CGRect)convertRect:(CGRect)rect toView:(UIView *)view;

// 將rect從view中轉(zhuǎn)換到當前視圖中,返回在當前視圖中的rect

  • (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view;

例把UITableViewCell中的subview(btn)的frame轉(zhuǎn)換到 controllerA中

// controllerA 中有一個UITableView, UITableView里有多行UITableVieCell,cell上放有一個button

// 在controllerA中實現(xiàn):

CGRect rc = [cell convertRect:cell.btn.frame toView:self.view];

CGRect rc = [self.view convertRect:cell.btn.frame fromView:cell];

// 此rc為btn在controllerA中的rect

或當已知btn時:

CGRect rc = [btn.superview convertRect:btn.frame toView:self.view];

CGRect rc = [self.view convertRect:btn.frame fromView:btn.superview];

弱引用的幾種寫法

weak typeof(&_self)weakSelf = self;

__weak __typeof(self) weakSelf = self;

__weak XxxViewController _weakSelf = self;

__weak id weakSelf = self;

CGImageRef與UIImage的的互轉(zhuǎn)

CGImage和CGImageRef這兩個應(yīng)當是用來重繪圖形的類,它們在應(yīng)用時是按照圖像的像素矩陣來繪制圖片的,它們可以用來處理位圖。

CGImageRef與UIImage的互轉(zhuǎn)

// CGImageRef轉(zhuǎn)換成UIImage CGImageRef

iOffscreen = CGBitmapContextCreateImage(context);

UIImage* image = [UIImage imageWithCGImage: iOffscreen];

// UIImage轉(zhuǎn)換成CGImageRef

UIImage *loadImage=[UIImage imageNamed:@"888.png"];

CGImageRef cgimage=loadImage.CGImage;

JPG和PNG圖片存儲沙盒

NSData *data;

if (UIImagePNGRepresentation(image) == nil) {

data = UIImageJPEGRepresentation(image, 1);

} else {

data = UIImagePNGRepresentation(image);

}

UIImagePNGRepresentation轉(zhuǎn)換PNG格式的圖片為二進制,如果圖片的格式為JPEG則返回零;

[fileManager createFileAtPath:[filePath stringByAppendingString:@"/image.png"] contents:data attributes:nil]; 將圖片保存為PNG格式

[fileManager createFileAtPath:[filePath stringByAppendingString:@"/image.jpg"] contents:data attributes:nil]; 將圖片保存為JPEG格式

我們也可以寫成下面的格式存儲圖片

NSString *pngImage = [filePath stringByAppendingPathComponent:@"Documents/image.png"];

NSString *jpgImage = [filePath stringByAppendingPathComponent:@"Documents/image.jpg"];

[data writeToFile:pngImage atomically:YES];

[data writeToFile:jpgImage atomically:YES];

修改按鍵上字體大小

button.titleLabel.font = [UIFont systemFontOfSize:28.0];

兩個經(jīng)緯度之間的相對距離

CLLocation *orig=[[CLLocation alloc] initWithLatitude:[mainDelegate.latitude_self doubleValue] longitude:[mainDelegate.longitude_self doubleValue]];

CLLocation* dist=[[CLLocation alloc] initWithLatitude:[tmpNewsModel.latitude doubleValue] longitude:[tmpNewsModel.longitude doubleValue]];

CLLocationDistance kilometers=[orig distanceFromLocation:dist]/1000;

NSLog(@"距離:",kilometers);

真機調(diào)試錯誤

獲得開發(fā)簽名后在真機器上部署測試
,在點擊構(gòu)建并運行后,提示該可執(zhí)行文件是無效的權(quán)利簽名。(在你的應(yīng)用程序的代碼簽名權(quán)利文件不匹配在置備配置文件中指定特定的權(quán)利。)錯誤- >(0xE8008016),

解決方法如下:

第一步:在工程中添加文件的新文件,選擇代碼簽名中的權(quán)利,添加后名稱為Entitlements.plist。

第二步:點擊Entitlements.plist進行編輯,刪除所有根下的密鑰,然后添加一個布爾類型,名稱為GET-任務(wù)允許的關(guān)鍵,狀態(tài)為CHECKED

第三步:在目標中的信息中的構(gòu)建選項卡中的代碼簽名權(quán)利的值設(shè)為Entitlements.plist,重新構(gòu)建即可解決

獲取視頻的第一幀圖片(用來在視頻列表默認顯示一個圖片)

  • (UIImage *)getFirstFrameOfVideoWithVideoURL:(NSURL *)videoURL

{

AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];

NSParameterAssert(asset);

AVAssetImageGenerator *assetIG = [[AVAssetImageGenerator alloc] initWithAsset:asset];

assetIG.appliesPreferredTrackTransform = YES;

assetIG.apertureMode = AVAssetImageGeneratorApertureModeEncodedPixels;

CGImageRef thumbnailImageRef = NULL;

CFTimeInterval thumbnailImageTime = 60;

NSError *igError = nil;

thumbnailImageRef = [assetIG copyCGImageAtTime:CMTimeMake(thumbnailImageTime, 60) actualTime:NULL error:&igError];

if (!thumbnailImageRef)

NSLog(@"thumbnailImageGenerationError %@", igError );

UIImage *thumbnailImage = thumbnailImageRef ? [[UIImage alloc] initWithCGImage:thumbnailImageRef] : nil;

return thumbnailImage;

}

故事情節(jié)中放置滾動型無法滾動的情況

  • (void)viewDidLayoutSubviews

{

[super viewDidLayoutSubviews];

self.mScrollView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);

self.mScrollView.contentSize = CGSizeMake(kScreenWidth, 568);

}

  • (void) viewDidAppear:(BOOL)animated

{

self.scrollView.frame = CGRectMake(0, 0, 320, 480);

[self.scrollView setContentSize:CGSizeMake(320, 1000)];

}

16進制顏色轉(zhuǎn)的UIColor

  • (UIColor *)colorFromHexString:(NSString *)hexString

{

if ([[hexString substringToIndex:1] isEqualToString:@"#"]) {

hexString = [hexString substringFromIndex:1];

}

unsigned rgbValue = 0;

NSScanner *scanner = [NSScanner scannerWithString:hexString];

[scanner scanHexInt:&rgbValue];

return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0];

}

按對應(yīng)的尺寸縮放圖片

  • (UIImage *)compressImage:(UIImage *)imgSrc withSize:(CGSize)size

{

UIGraphicsBeginImageContext(size);

CGRect rect = {{0,0}, size};

[imgSrc drawInRect:rect];

UIImage *compressedImg = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return compressedImg;

}

GIF圖片轉(zhuǎn)化成一個存儲圖像對象的數(shù)組

frame(幀):一個gif可以簡單認為是多張image組成的動畫,一幀就是其中一張圖片image.
frameCount(幀數(shù)): 就是一個gif有多少幀
loopCount(播放次數(shù)):有些gif播放到一定次數(shù)就停止了,如果為0就代表gif一直循環(huán)播放。
delayTime(延遲時間):每一幀播放的時間,也就是說這幀顯示到delayTime就轉(zhuǎn)到下一幀。
所以gif播放主要就是把每一幀image解析出來,然后每一幀顯示它對應(yīng)的delaytime,然后再顯示下一張。如此循環(huán)下去。
下面是純粹實現(xiàn)由系統(tǒng)提供的解碼:
-(void)decodeWithFilePath:(NSString *)filePath
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^() {

NSData *data = [NSData dataWithContentsOfFile:self.path];

[self decodeWithData:data];
});
}

  • (void)decodeWithData:(NSData *)data
    {
    CGImageSourceRef src = CGImageSourceCreateWithData((CFDataRef) data, NULL); if (src)
    {
    //獲取gif的幀數(shù) NSUInteger frameCount = CGImageSourceGetCount(src); //獲取GfiImage的基本數(shù)據(jù) NSDictionary *gifProperties = (NSDictionary *) CGImageSourceCopyProperties(src, NULL); if(gifProperties)
    {
    //由GfiImage的基本數(shù)據(jù)獲取gif數(shù)據(jù)

NSDictionary gifDictionary =[gifProperties objectForKey:(NSString)kCGImagePropertyGIFDictionary];

//獲取gif的播放次數(shù)

NSUInteger loopCount = [[gifDictionary objectForKey:(NSString*)kCGImagePropertyGIFLoopCount] integerValue];

for (NSUInteger i = 0; i < frameCount; i++)
{
//得到每一幀的CGImage CGImageRef img = CGImageSourceCreateImageAtIndex(src, (size_t) i, NULL); if (img)
{
//把CGImage轉(zhuǎn)化為UIImage UIImage *frameImage = [UIImage imageWithCGImage:img]; //獲取每一幀的圖片信息 NSDictionary *frameProperties = (NSDictionary ) CGImageSourceCopyPropertiesAtIndex(src, (size_t) i, NULL); if (frameProperties)
{
//由每一幀的圖片信息獲取gif信息 NSDictionary frameDictionary = [frameProperties objectForKey:(NSString)kCGImagePropertyGIFDictionary]; //取出每一幀的delaytime CGFloat delayTime = [[frameDictionary objectForKey:(NSString
)kCGImagePropertyGIFDelayTime] floatValue]; //TODO 這里可以實現(xiàn)邊解碼邊回調(diào)播放或者把每一幀image和delayTime存儲起來 CFRelease(frameProperties);
}
CGImageRelease(img);
}
}
CFRelease(gifProperties);
}
CFRelease(src);
}
}

使用NSCountedSet統(tǒng)計重復元素的個數(shù)

可能你會發(fā)現(xiàn)這個類的父類是的NSMutableSet納尼不是說的NSMutableSet是不可以儲存重復對象的嗎其實NSCountedSet也是不能儲存重復的對象的,查看蘋果文檔中對這個類的描述有這么一句?:

插入NSCountedSet對象每個不同對象具有與之相關(guān)聯(lián)的計數(shù)器。

插入NSCountedSet對象的每個不同的對象都有一個與之相關(guān)的計數(shù)器

也就是說如果遇到重復對象的加入,這個對象的計數(shù)器就會+1。所以可以到這個類有個名叫

  • (NSUInteger)countForObject:(id)object 的方法來統(tǒng)計重復對象的個數(shù)。

NSArray *array = @[@1, @2, @2, @1];

NSCountedSet *set = [[NSCountedSet alloc]initWithArray:array];

[set enumerateObjectsUsingBlock:^(id obj, BOOLBOOL *stop) {

NSLog(@"%@ => %d", obj, [set countForObject:obj]);

}];

導航條返回鍵帶的標題太討厭了,怎么讓它消失

[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];

截屏轉(zhuǎn)化為圖像

UIGraphicsBeginImageContext(self.view.bounds.size);

[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage *image= UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);

  • (UIImage *)creatImageWithView:(UIView *)view rect:(CGRect)rect

{

CGSize size = view.bounds.size;

UIGraphicsBeginImageContextWithOptions(size, NO, 0);

[view.layer renderInContext:UIGraphicsGetCurrentContext()];

UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

CGImageRef viewImageRef = viewImage.CGImage;

CGImageRef imageRef = CGImageCreateWithImageInRect(viewImageRef, rect);

UIImage *image = [[UIImage alloc] initWithCGImage:imageRef];

CGImageRelease(imageRef);

return image;

}

storybord中設(shè)置靜態(tài)單元格時候,一定要把代碼中的數(shù)據(jù)源的兩個方法注掉,不然是不會顯示的。還有就是,廈門國際銀行上貌似不能用靜態(tài)單元格,storybord可以

自定義視圖時候獲取該視圖的導航控制器和視圖控制器

  • (UIViewController)viewController { for (UIView next = [self superview]; next; next = next.superview) { UIResponder* nextResponder = [next nextResponder]; if ([nextResponder isKindOfClass:[UINavigationController class]]) { return (UIViewController)nextResponder;
    }
    }
    return nil;
    }
    //獲取導航控制器- (UINavigationController
    )navigationController { for (UIView* next = [self superview]; next; next = next.superview) { UIResponder* nextResponder = [next nextResponder]; if ([nextResponder isKindOfClass:[UINavigationController class]]) { return (UINavigationController*)nextResponder;
    }
    }
    return nil;
    }
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容