目錄
- maskView動(dòng)畫原理 :遮罩
- button倒計(jì)時(shí)閃爍解決
- 改變從xib拖出來(lái)約束多糠,沒(méi)有動(dòng)畫效果解決辦法:添加 layoutIfNeeded
- 去除導(dǎo)航欄底部1px橫線
- UIWebView直接打開PDF文件
- 改變StatusBar顏色
- UICollectionView 和 UITableView 頂部留白處理
- TableView底下多余的分割線去除
- webView真正加載完成
- UIButton 只有title的時(shí)候拗盒,把 title 靠左對(duì)齊
- Restoration ID 和 UITableViewCell 的identifier的區(qū)別
- UIButton 的 SEL 換成block
- UIImage指定范圍內(nèi)拉伸 - 聊天氣泡背景圖
- NSAttributeString設(shè)置文本位置居中伴箩、靠左
- 打開系統(tǒng)相機(jī)、使用searchBarController等 標(biāo)題顯示英文解決
- label 設(shè)置文字漸變色 [設(shè)置漸變色幾種方式]
- 設(shè)置導(dǎo)航欄上返回圖標(biāo)和title為空
- Could not load NIB in bundle 錯(cuò)誤。 nib文件存在整陌,找不到,原因是沒(méi)有選中 'Target Membership'
- Mac OS 系統(tǒng)更新到了 high Sierra 瞎领,pod 不能用了 報(bào)錯(cuò)
- 文本轉(zhuǎn)語(yǔ)音播放
- present出來(lái)一個(gè)半透明的view controller
- NSAspects 使用
- UITextField 明文密文切換光標(biāo)位置不準(zhǔn)
- UITextField 右對(duì)齊在末尾輸入空格不顯示
- 禁用第三方鍵盤
- OC計(jì)算字符串中字符個(gè)數(shù)(漢字2個(gè)字符泌辫,英文字母、數(shù)字九默、空格1個(gè)字符)
- iOS 啟動(dòng)圖問(wèn)題
- 簡(jiǎn)書生成圖片分享iOS實(shí)現(xiàn)
- bundle name 和 bundle display name
- Localizations中Resources中顯示0 files Localized
- 獲取當(dāng)前系統(tǒng)語(yǔ)言
- 打包上傳APP到iTunes connect時(shí)候出錯(cuò)震放。
- UIPickerView UIDatePicker 分割線去除
- 各一個(gè)有圓角的view添加陰影效果
- 設(shè)置按鈕不可點(diǎn)擊狀態(tài)時(shí)的背景色,顏色有誤差驼修。原因是系統(tǒng)自動(dòng)加了層蒙版殿遂。
- 自定義返回按鈕導(dǎo)致系統(tǒng)的右滑返回手勢(shì)失效
- 隱藏導(dǎo)航欄
- pop到上上一級(jí)vc
- uitextfield輸入內(nèi)容過(guò)長(zhǎng)時(shí)候诈铛,字符不自動(dòng)左移問(wèn)題
- 導(dǎo)航欄上添加視圖frame問(wèn)題
- 同時(shí)重寫setter getter ,實(shí)例變量報(bào)錯(cuò)問(wèn)題
- 選擇模擬器/真機(jī),顯示no scheme
- Xcode增加編譯環(huán)境 debug release 新增preProduct
- UITextField光標(biāo)換成圖片
- 封裝pod庫(kù)時(shí)帶上資源bundle
- UISider滑動(dòng)和pan手勢(shì)滑動(dòng)沖突
- 鍵盤彈起自動(dòng)上滑tableview
- Cancle換成漢字『取消』
- 日期格式化 https://www.cnblogs.com/Cristen/p/3599922.html
- 已經(jīng)納入版本管理的文件,加入.gitignore不生效的問(wèn)題
- git添加子模塊submodule
- git移除子模塊
- 去除main.storyboard
- cell選中時(shí)峻厚,子視圖背景顏色受影響
- didselected方法不管用
隨手記
maskView動(dòng)畫原理 :遮罩
-
button倒計(jì)時(shí)閃爍解決
把按鈕樣式設(shè)為custom而非system
-
把下面代碼中注釋掉的兩行放開
-(void)ticktack { __block int timeout = 59; dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue); dispatch_source_set_timer(_timer, dispatch_walltime(NULL, 0), 1.0*NSEC_PER_SEC, 0); dispatch_source_set_event_handler(_timer, ^{ dispatch_async(dispatch_get_main_queue(), ^{ if (timeout <= 0) {//倒計(jì)時(shí)結(jié)束,關(guān)閉 dispatch_source_cancel(_timer); // self.sendCodeBtn.titleLabel.text = @"獲取驗(yàn)證碼"; [self.sendCodeBtn setTitle:@"獲取驗(yàn)證碼" forState:UIControlStateNormal]; self.sendCodeBtn.userInteractionEnabled = YES; self.sendCodeBtn.enabled = YES; } else { // self.sendCodeBtn.titleLabel.text = [NSString stringWithFormat:@"%d秒后重新發(fā)送",timeout]; [self.sendCodeBtn setTitle:[NSString stringWithFormat:@"%d秒后重新發(fā)送",timeout] forState:UIControlStateNormal]; self.sendCodeBtn.userInteractionEnabled = NO; self.sendCodeBtn.enabled = NO; timeout--; } }); }); dispatch_resume(_timer); }
-
改變從xib拖出來(lái)約束焕毫,沒(méi)有動(dòng)畫效果解決辦法:添加 layoutIfNeeded
[UIView animateWithDuration:0.5 animations:^{ self.passwdLoginContainLeadingContain.constant = -ScreenWidth; [self.view layoutIfNeeded]; } completion:^(BOOL finished) { }];
-
去除導(dǎo)航欄底部1px橫線
UINavigationBar *navBar = self.navigationController.navigationBar; [navBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault]; [navBar setShadowImage:[UIImage new]];
-
UIWebView直接打開PDF文件
NSURLRequest *req = [NSURLRequest alloc] initWithUrl:[NSURL urlWithfilePath:filePath]]; webView.scalesPageToFit = YES; webView.loadRequest
-
改變StatusBar顏色
UINavigationBar *navBar = self.navigationController.navigationBar; _statusView = [[UIView alloc] initWithFrame:CGRectMake(0, -20, ScreenWidth, 20)]; _statusView.backgroundColor = [UIColor colorWithRed:241/255.0 green:241/255.0 blue:241/255.0 alpha:1]; [navBar addSubview:_statusView];
-
UICollectionView 和 UITableView 頂部留白處理
self.automaticallyAdjustsScrollViewInsets = NO
-
TableView底下多余的分割線去除
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
-
webView真正加載完成
webViewDidFinishLoad: 方法在頁(yè)面重定向的時(shí)候會(huì)被多次加載,用webView.isLoading判斷是否還在加載
-
UIButton 只有title的時(shí)候驶乾,把 title 靠左對(duì)齊
btn.contentHorizontalAlignment = UIControlContentHorizontalAlignment.left // btn.titleLabel?.textAlignment = NSTextAlignment.left 這句不管用
Restoration ID 和 UITableViewCell 的identifier的區(qū)別
- Restoration ID Preserving and Restoring State
用于存儲(chǔ)和恢復(fù)應(yīng)用狀態(tài)邑飒。一個(gè)應(yīng)用進(jìn)入后臺(tái),再進(jìn)入前臺(tái)顯示的還是之前的頁(yè)面级乐,優(yōu)化用戶體驗(yàn) - Identifer 用于從xib或者故事版里創(chuàng)建一個(gè)實(shí)例
- UIButton 的 SEL 換成block
@class QSBlockButton;
#pragma mark class QSBlockButton
typedef void(^ActionBlock)(QSBlockButton *);
@interface QSBlockButton : UIButton
@property (copy, nonatomic) ActionBlock block;
@end
@implementation QSBlockButton
- (instancetype)init {
self = [super init];
if (self) {
[self addTarget:self action:@selector(touchAction:) forControlEvents:UIControlEventTouchUpInside];
}
return self;
}
- (void)touchAction:(id)sender{
_block(self);
}
-
UIImage指定范圍內(nèi)拉伸 - 聊天氣泡背景圖
UIImage *imgBack = [bkImg stretchableImageWithLeftCapWidth:0 topCapHeight:2];
NSAttributeString設(shè)置文本位置居中疙咸、靠左
NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc]init];
paragraph.alignment = NSTextAlignmentJustified;
NSDictionary *dic = @{NSParagraphStyleAttributeName : paragraph]};
打開系統(tǒng)相機(jī)、使用searchBarController等 標(biāo)題顯示英文解決:在
info.plist
中添加Localized resources can be mixed
設(shè)為YES
-
label 設(shè)置文字漸變色 設(shè)置漸變色幾種方式
方式一 : NSArray *gradientColors = @[(id)ColorFromRGB(0xff7f43).CGColor, (id)ColorFromRGB(0xff3609).CGColor]; _titleLabel = [[UILabel alloc] init]; self.titleLabel.text = title; self.titleLabel.font = [UIFont systemFontOfSize:12]; [self.titleLabel sizeToFit]; if (self.titleLabel.frame.size.width > self.rightView.frame.size.width) { self.titleLabel.frame = CGRectMake(0, 0, self.rightView.frame.size.width, self.rightView.frame.size.height); } else { self.titleLabel.frame = CGRectMake(self.rightView.frame.size.width - _titleLabel.frame.size.width, (self.rightView.frame.size.height-_titleLabel.frame.size.height)/2, _titleLabel.frame.size.width, _titleLabel.frame.size.height); } [self.rightView addSubview:self.titleLabel]; // 創(chuàng)建漸變層 CAGradientLayer *gradientLayer = [CAGradientLayer layer]; gradientLayer.frame = self.titleLabel.frame; gradientLayer.colors = gradientColors; gradientLayer.startPoint = CGPointMake(0, 1); gradientLayer.endPoint = CGPointMake(1, 1); NSArray *layers = self.rightView.layer.sublayers; NSMutableArray *murr = [NSMutableArray arrayWithArray:layers]; for (CALayer *l in murr) { if ([l isKindOfClass:[CAGradientLayer class]]) { [l removeFromSuperlayer]; } } [self.rightView.layer addSublayer:gradientLayer]; gradientLayer.mask = self.titleLabel.layer; self.titleLabel.frame = gradientLayer.bounds;
-
設(shè)置導(dǎo)航欄上返回圖標(biāo)和title為空
self.navigationController?.navigationBar.backIndicatorImage = #imageLiteral(resourceName: "back").withRenderingMode(.alwaysOriginal) self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
-
Could not load NIB in bundle 錯(cuò)誤唇牧。 nib文件存在罕扎,找不到,原因是沒(méi)有選中 'Target Membership'
-
Mac OS 系統(tǒng)更新到了 high Sierra 丐重,pod 不能用了 報(bào)錯(cuò):
-bash: /usr/local/bin/pod: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby: bad interpreter: No such file or directory
解決:重新安裝cocoapods ‘sudo gem install cocoapods’
-
文本轉(zhuǎn)語(yǔ)音播放
let utterance = AVSpeechUtterance.init(string: "Hello,我覺(jué)得吧...") let synthesizer = AVSpeechSynthesizer.init() synthesizer.speak(utterance)
NSTimer后臺(tái)運(yùn)行
- (void)viewDidLoad {
[super viewDidLoad];
_count = 10;
[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:nil];
_timer =[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(ticktock:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:_timer forMode:(NSRunLoopCommonModes)];
}
- (void)ticktock:(NSTimer *)sender {
if (_count > 0) {
_count--;
_label.text = [NSString stringWithFormat:@"%ld",_count];
NSLog(@"%@",_label.text);
}
else {
[_timer invalidate];
}
}
-
present出來(lái)一個(gè)半透明的view controller
DSBirthdayViewController *birthdayVC = [[DSBirthdayViewController alloc] init]; birthdayVC.modalPresentationStyle = UIModalPresentationOverCurrentContext; [self presentViewController:birthdayVC animated:YES completion:^{ }];
-
NSAspects 使用
[NSAspects hookMethodForObject:people selector:@selector(drink) withOptions:(AspectPositionInstead | AspectOptionAutomaticRemoval ) usingBlock:^(void){ NSLog(@"eat"); } error:nil];
UITextField 明文密文切換光標(biāo)位置不準(zhǔn)
兩種解決方式: 1. 注釋中語(yǔ)句 2. if 里語(yǔ)句
-
UITextField 右對(duì)齊在末尾輸入空格不顯示
//1. 自定義TextField // .h @interface MTTextField : UITextField @end //.m @implementation MTTextField - (instancetype)init { self = [super init]; if (self) { [self addTarget:self action:@selector(replaceNormalSpaceUsingNonbreakingSpace) forControlEvents:UIControlEventEditingChanged]; } return self; } - (void)replaceNormalSpaceUsingNonbreakingSpace { UITextRange *textRange = self.selectedTextRange; self.text = [self.text stringByReplacingOccurrencesOfString:@" " withString:@"\u00a0"]; [self setSelectedTextRange:textRange]; } //2. 使用的時(shí)候 [[MTObserve(cell.textField, text) skip:1] subscribeNext:^(NSString *x) { @strongify(self) NSString *text = [x stringByReplacingOccurrencesOfString:@"\u00a0" withString:@" "]; self.modifyInfoViewModel.nickname = [text trim]; }];
-
禁用第三方鍵盤
//全局禁第三方鍵盤 - (BOOL)application:(UIApplication *)application shouldAllowExtensionPointIdentifier:(NSString *)extensionPointIdentifier { return NO; } //某個(gè)uitextfield禁第三方鍵盤 [原文](https://www.pixotech.com/ios8_third_party_custom_keyboard_compatibility/) #pragma mark - 禁用三方鍵盤 - (BOOL)application:(UIApplication *)application shouldAllowExtensionPointIdentifier:(NSString *)extensionPointIdentifier { if ([extensionPointIdentifier isEqualToString: UIApplicationKeyboardExtensionPointIdentifier]) { id responder = [self findFirstResponder]; if ([responder isKindOfClass:[UITextField class]]) { return NO; } } return YES; } id mt_firstResponder; -(id)findFirstResponder { mt_firstResponder = nil; [[UIApplication sharedApplication] sendAction:@selector(foundFirstResponder:) to:nil from:nil forEvent:nil]; return mt_firstResponder; } -(void)foundFirstResponder:(id)sender { mt_firstResponder = self; }
-
OC計(jì)算字符串中字符個(gè)數(shù)(漢字2個(gè)字符腔召,英文字母、數(shù)字扮惦、空格1個(gè)字符)
- (NSUInteger)textLength: (NSString *) text { NSUInteger asciiLength = 0; for (NSUInteger i = 0; i < text.length; i++) { unichar uc = [text characterAtIndex: I]; asciiLength += isascii(uc) ? 1 : 2; } NSUInteger unicodeLength = asciiLength; return unicodeLength; }
-
iOS 啟動(dòng)圖問(wèn)題
確認(rèn)各項(xiàng)配置都正確臀蛛,但是啟動(dòng)圖就是不出來(lái)。試試刪除app崖蜜,然后重啟手機(jī)???♂?浊仆。
Gernal 配置 App Icon and Launch Images 一項(xiàng)時(shí)候。使用 Launch Image Source. 而不是 Launch Screen File 時(shí)候豫领。要把 4寸屏幕的啟動(dòng)圖也加上抡柿,不然會(huì)導(dǎo)致在 4寸屏幕手機(jī)上運(yùn)行時(shí)候,上下有黑色等恐。
- 簡(jiǎn)書生成圖片分享iOS實(shí)現(xiàn)
// 內(nèi)容都放到textView里
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextView *textView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction)action:(id)sender {
UIImage *image = [self imageWithScreenContentsInView:_textView];
UIImageWriteToSavedPhotosAlbum(image, self, @selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:), nil);
}
//在指定的視圖內(nèi)進(jìn)行截屏操作,返回截屏后的圖片
-(UIImage *)imageWithScreenContentsInView:(UIView *)view
{
//根據(jù)屏幕大小洲劣,獲取上下文
UIGraphicsBeginImageContext(_textView.contentSize);
[_textView.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSLog(@"\n=======%@=========\n",NSStringFromClass([obj class]));
if ([NSStringFromClass([obj class]) isEqualToString:@"_UITextContainerView"]) {
[obj.layer renderInContext:UIGraphicsGetCurrentContext()];
}
}];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return viewImage;
}
- (void)imageSavedToPhotosAlbum:(UIImage*)image didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo{
if(!error) {
NSLog(@"合影已保存到相冊(cè)");
}else{
NSLog(@"合影保存失敗");
}
}
@end
- bundle name 和 bundle display name
bundle name
is folder name, where your app (including executable file and all resources) will be stored (Cool Program.app)。建議不要修改bundle name (http://blog.csdn.net/kkk0526/article/details/9198355)bundle display name
is what will be shown on iPhone screen课蔬,即當(dāng)你安裝該app到iPhone上顯示的name囱稽。 (http://blog.csdn.net/kkk0526/article/details/9198355)
- Localizations中Resources中顯示0 files Localized
原因:這是因?yàn)榘裮ain.storyboard LaunchImage.storyboard 都刪除了。這時(shí)候想要添加國(guó)際化語(yǔ)言因?yàn)槭?所以添加不了扎即。
解決:暫時(shí)添加個(gè)LaunchImage.storyboard吞获,等國(guó)際化做好后况凉,就可以刪掉了。
- 獲取當(dāng)前系統(tǒng)語(yǔ)言
- (BOOL)isRightLanguages {
NSString *current = [[NSLocale preferredLanguages] objectAtIndex:0];//當(dāng)前語(yǔ)言 h-Hans-CN 簡(jiǎn)體中文, zh-Hant-MO繁體中文, en-CN 英文
NSArray *supports = [[NSUserDefaults standardUserDefaults]objectForKey:@"AppleLanguages"];
BOOL is = NO;
for (NSString *sub in supports) {
if ([sub isEqualToString:current]) {
is = YES;
}
}
return is;
}
-
打包上傳APP到iTunes connect時(shí)候出錯(cuò)衫哥。
ERROR ITMS-90475: "Invalid Bundle. Your app supports Multitasking on iPad, so you must include the UILaunchStoryboardName key in your bundle, 'com.sun.allen.app’. Learn more (https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW40)."
解決:
-
UIPickerView UIDatePicker 分割線去除
// date picker 分割線去除 self.datePicker.subviews.firstObject.subviews - (void)clearSeparatorView { [self.datePicker.subviews.firstObject.subviews enumerateObjectsUsingBlock:^( UIView *obj, NSUInteger idx, BOOL * stop) { if (obj.frame.size.height < 1) { obj.hidden = YES; } }]; } //UIPickerView 分割線去除 - (void)clearSeparatorView { [self.genderPickerView.subviews enumerateObjectsUsingBlock:^( UIView *obj, NSUInteger idx, BOOL * stop) { if (obj.frame.size.height < 1) { obj.hidden = YES; } }]; }
各一個(gè)有圓角的view添加陰影效果
MTDealSaleCardView *card = [[MTDealSaleCardView alloc] init];
card.layer.cornerRadius = 4.f;
// card view 的 masksToBounds = YES; 會(huì)把陰影效果也切掉茎刚。所以要給它增加一個(gè)父視圖,對(duì)父視圖做陰影效果
card.layer.masksToBounds = YES;
card.layer.borderColor = [UIColor colorWithHexString:@"#e4e4e4"].CGColor;
card.layer.borderWidth = 0.5;
/**
創(chuàng)建一個(gè)cardContainerView盛放card , 對(duì) cardContainerView 做陰影效果
@param card card
@return card的父視圖
*/
- (UIView *)createCardShadowEffect:(MTDealSaleCardView *)card {
UIView *cardContainerView = [[UIView alloc] init];
[cardContainerView addSubview:card];
[card mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.right.bottom.equalTo(cardContainerView);
}];
//陰影
cardContainerView.layer.shadowColor = [UIColor colorWithHexString:@"0f000000"].CGColor;
cardContainerView.layer.shadowColor = [UIColor yellowColor].CGColor; //todo
cardContainerView.layer.shadowOffset = CGSizeMake(0, 0);
cardContainerView.layer.shadowRadius = 4.f;
cardContainerView.layer.shadowOpacity = 1;
UIBezierPath *path = [UIBezierPath bezierPath];
CGFloat addWH = 4.f;
CGFloat selfWidth = MTRealTimePriceTableViewCell_CardWidth;
CGFloat selfHeight = MTRealTimePriceTableViewCell_CardHeight;
CGPoint topLeft = CGPointMake(0, 0);
CGPoint topMiddle = CGPointMake(selfWidth/2, -addWH);
CGPoint topRight = CGPointMake(selfWidth, 0);
CGPoint leftMiddle = CGPointMake(-addWH, selfHeight/2);
CGPoint leftBottom = CGPointMake(0, selfHeight);
CGPoint rightMiddel = CGPointMake(selfWidth+addWH, selfHeight/2);
CGPoint rightBottom = CGPointMake(selfWidth, selfHeight);
CGPoint bottomMiddel = CGPointMake(selfWidth/2, selfHeight+addWH);
[path moveToPoint:topLeft];
[path addQuadCurveToPoint:topRight controlPoint:topMiddle];
[path addQuadCurveToPoint:rightBottom controlPoint:rightMiddel];
[path addQuadCurveToPoint:leftBottom controlPoint:bottomMiddel];
[path addQuadCurveToPoint:topLeft controlPoint:leftMiddle];
cardContainerView.layer.shadowPath = path.CGPath;
cardContainerView.backgroundColor = [UIColor whiteColor];
return cardContainerView;
}
- 設(shè)置按鈕不可點(diǎn)擊狀態(tài)時(shí)的背景色撤逢,顏色有誤差。原因是系統(tǒng)自動(dòng)加了層蒙版粮坞。
解決:不使用state蚊荣,而是通過(guò)修改button的是否可交互屬性。
//此處不使用按鈕綁定command莫杈,而是控制按鈕的userInteractionEnabled互例。
//原因是使用綁定command時(shí)候,直接設(shè)置按鈕UIControlStateDiabled的背景顏色筝闹,系統(tǒng)會(huì)自動(dòng)加上一層蒙版 導(dǎo)致顏色值不對(duì)媳叨。
// self.rechargeButton.rac_command = self.viewModel.rechargeCommand;
[self.viewModel.rechargeCommand.enabled subscribeNext:^(NSNumber *x) {
@strongify(self)
if (x.boolValue) {
self.rechargeButton.userInteractionEnabled = YES;
[self.rechargeButton setBackgroundImage:[UIImage imageWithColor:MTThemeColor]
forState:(UIControlStateNormal)];
[self.rechargeButton setTitleAttributes:@{NSFontAttributeName: [UIFont mediumSystemFontOfSize:15], NSForegroundColorAttributeName: [UIColor colorWithHexString:@"#333333"]}
forState:(UIControlStateNormal)];
} else {
self.rechargeButton.userInteractionEnabled = NO;
[self.rechargeButton setBackgroundImage:[UIImage imageWithColor:[UIColor colorWithHexString:@"ececec"]]
forState:(UIControlStateNormal)];
[self.rechargeButton setTitleAttributes:@{NSFontAttributeName: [UIFont mediumSystemFontOfSize:15], NSForegroundColorAttributeName: [UIColor colorWithHexString:@"#c5c5c5"]}
forState:(UIControlStateNormal)];
}
}];
[[self.rechargeButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
@strongify(self)
[self.viewModel.rechargeCommand execute:nil];
}];
-
自定義返回按鈕導(dǎo)致系統(tǒng)的右滑返回手勢(shì)失效
// 添加上這一行就解決了 self.navigationController.interactivePopGestureRecognizer.delegate = (id)self; // - (void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; if (self.navigationController.viewControllers.count > 1) { self.navigationController.interactivePopGestureRecognizer.enabled = YES; }else{ self.navigationController.interactivePopGestureRecognizer.enabled = NO; } }
-
pop到上上一級(jí)vc
for (NSInteger i = 0; i<self.navigationController.childViewControllers.count; i++) { UIViewController *child = [self.navigationController.childViewControllers objectOrNilAtIndex:i]; if ([child isKindOfClass:[MTApplyRedemptionViewController class]]) { NSMutableArray *tempArr = [NSMutableArray arrayWithArray:self.navigationController.childViewControllers]; [tempArr removeObject:child]; [self.navigationController setViewControllers:tempArr]; break; } }
uitextfield輸入內(nèi)容過(guò)長(zhǎng)時(shí)候,字符不自動(dòng)左移問(wèn)題 iOS10以下
解決: 增加uitextfield高度
- 導(dǎo)航欄上添加視圖frame問(wèn)題
- (SSPageControl *)pageControl {
if (!_pageControl) {
_pageControl = [[SSPageControl alloc] initWithFrame:CGRectMake(0, 0, 106, 4)];//106是有9張圖片的時(shí)候的最大寬度 .//必須一開始就把寬度寫死关顷,如果動(dòng)態(tài)改變的話會(huì)導(dǎo)致iOS10上 pageControl跳動(dòng)
_pageControl.userInteractionEnabled = NO;
_pageControl.controlNormalSize = 4.f;
_pageControl.controlCurrentSize = 10.f;
_pageControl.controlSpacing = 8.f;
_pageControl.otherBkImg = [UIImage imageWithColor:[UIColor colorWithHexString:@"ffffff50"]];
_pageControl.currentBkImg = [UIImage imageWithColor:[UIColor colorWithHexString:@"ffffff"]];
_pageControl.hidden = YES;
}
return _pageControl;
}
- (void)configurationPageControl {
self.pageControl.numberOfPages = self.viewModel.imageArray.count;
self.pageControl.currentPage = 0;
CGFloat width = [self.pageControl sizeThatFits:CGSizeZero].width;
CGFloat height = self.pageControl.controlNormalSize;
// self.pageControl.frame = CGRectMake(0.0, 0.0, width, height); //不能動(dòng)態(tài)的改變frame
self.pageControl.hidden = (self.viewModel.imageArray.count == 1);
}
self.navigationItem.titleView = self.pageControl;
-
同時(shí)重寫setter getter 糊秆,實(shí)例變量報(bào)錯(cuò)問(wèn)題
選擇模擬器/真機(jī),顯示no scheme
[解決 點(diǎn)擊 NO Scheme议双,新增一個(gè)] (https://blog.csdn.net/QearlYu/article/details/53466699)
- Xcode增加編譯環(huán)境 debug release 新增preProduct
https://blog.csdn.net/FreshManCode/article/details/80354936
- UITextField光標(biāo)換成圖片
- 封裝pod庫(kù)時(shí)帶上資源bundle
獲取bundle
+ (NSBundle *)ucar_resourceBundle {
NSBundle *bundle = [NSBundle bundleForClass:[TestProjClass class]];
NSURL *url = [bundle URLForResource:@"testProj" withExtension:@"bundle"];
bundle = [NSBundle bundleWithURL:url];
return bundle;
}
獲取圖片
+ (UIImage *)getImg {
NSLog(@"哈哈哈哈");
NSBundle *bundle = [NSBundle ucar_resourceBundle];
UIImage *image = [UIImage imageNamed:@"ucar_pause.png" inBundle:bundle compatibleWithTraitCollection:nil];
return image;
}
podspec文件中寫好bundle路徑痘番,把pod庫(kù)發(fā)布出去
s.resource_bundles = {
'testProj' => ['testProj/testProj/testProj/testProj.bundle'],
}
使用示例如下:
-
UISider滑動(dòng)和pan手勢(shì)滑動(dòng)沖突
#pragma mark - UIGestureRecognizerDelegate -(BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer shouldReceiveTouch:(UITouch*)touch { if ([gestureRecognizer isEqual:self.panGR] && [touch.view isEqual:self.progressSilder]) { return NO;// 防止pan手勢(shì)影響UISlider的響應(yīng) } return YES; }
鍵盤彈起自動(dòng)上滑tableview
- (void)registerForKeyboardNotifications {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)keyboardWillShow:(NSNotification *)aNotification {
NSDictionary* info = [aNotification userInfo];
// 注意不要用UIKeyboardFrameBeginUserInfoKey,第三方鍵盤可能會(huì)存在高度不準(zhǔn)平痰,相差40高度的問(wèn)題
CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
// 修改滾動(dòng)天和tableView的contentInset
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, kbSize.height, 0);
self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, kbSize.height, 0);
// 跳轉(zhuǎn)到當(dāng)前點(diǎn)擊的輸入框所在的cell
[UIView animateWithDuration:0.2 animations:^{
[self.tableView scrollToRowAtIndexPath:self.beginEditIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];
}];
}
- (void)keyboardWillBeHidden:(NSNotification *)aNotification {
self.tableView.contentInset = UIEdgeInsetsZero;
self.tableView.scrollIndicatorInsets = UIEdgeInsetsZero;
}
- Cancle換成漢字『取消』
修改info.plist中 "Localization native development region" 成 "China"
已經(jīng)納入版本管理的文件汞舱,加入.gitignore不生效的問(wèn)題
.gitignore只能忽略那些原來(lái)沒(méi)有被track的文件,如果某些文件已經(jīng)被納入了版本管理中宗雇,則修改.gitignore是無(wú)效的昂芜。
只能clone到本地,刪除后赔蒲,再進(jìn)行忽略泌神。
- git添加子模塊submodule
$ git submodule add https://github.com/xxx.git
Cloning into 'xxx'...
remote: Counting objects: 11, done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 11 (delta 0), reused 11 (delta 0)
Unpacking objects: 100% (11/11), done.
Checking connectivity... done.
- git移除子模塊
-
cd .git
切換到.git目錄,修改config嘹履,刪掉submodule
-
cd modules
腻扇,刪除子模塊目錄 -
cd 項(xiàng)目根目錄
刪除子模塊目錄
- 去除main.storyboard
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let win = UIWindow.init(frame: UIScreen.main.bounds)
win.rootViewController = BWRootTabBarController()
win.backgroundColor = UIColor.white
win.makeKeyAndVisible()
self.window = win
return true
}
- cell選中時(shí),子視圖背景顏色受影響
- (void)layoutSubviews {
[super layoutSubviews];
self.statusLabel.backgroundColor = [UIColor colorWithHexRGBAString:@"#FF5B45"];
}
- didselected方法不管用
- item/cell上有button或者手勢(shì)響應(yīng)了點(diǎn)擊事件
Xcode配置
debug包沒(méi)問(wèn)題砾嫉、release包出問(wèn)題原因幼苛。解決方法: 打Release包的時(shí)候把 Optimization Level 改成 None, Debug 模式默認(rèn)就是 None 所以才沒(méi)問(wèn)題焕刮。
’The file “XXX.app” couldn’t be opened because you don’t have permission to view it.‘ 解決辦法: info文件中的字段 Executable file 改成$(PRODUCT_NAME)舶沿。 ????
[App] if we're in the real pre-commit handler we can't actually add any new fences due to CA restriction
解決:
其他
-
ARC環(huán)境中使用weak 的修飾符來(lái)修飾一個(gè)變量墙杯,防止其在block中被循環(huán)引用,而有些特殊情況下括荡,我們?cè)赽lock中又使用_strong 來(lái)修飾這個(gè)在block外剛剛用_weak修飾的變量高镐,這是因?yàn)樵赽lock中調(diào)用self會(huì)引起循環(huán)引用,而在block中需要對(duì)weakSelf進(jìn)行__strong,保證代碼在執(zhí)行到block中畸冲,self不會(huì)被釋放嫉髓,當(dāng)block執(zhí)行完后,會(huì)自動(dòng)釋放該strongSelf
eg: AFNetworkReachabilityManager.m 文件中 __weak __typeof(self)weakSelf = self; AFNetworkReachabilityStatusBlock callback = ^(AFNetworkReachabilityStatus status) { __strong __typeof(weakSelf)strongSelf = weakSelf; strongSelf.networkReachabilityStatus = status; if (strongSelf.networkReachabilityStatusBlock) { strongSelf.networkReachabilityStatusBlock(status); } };
block一般用copy修飾邑闲。block 使用 copy 是從 MRC 遺留下來(lái)的“傳統(tǒng)”,在 MRC 中,方法內(nèi)部的 block 是在棧區(qū)的,使用 copy 可以把它放到堆區(qū).在 ARC 中寫不寫都行:對(duì)于 block 使用 copy 還是 strong 效果是一樣的算行,但寫上 copy 也無(wú)傷大雅,還能時(shí)刻提醒我們:編譯器自動(dòng)對(duì) block 進(jìn)行了 copy 操作苫耸。如果不寫 copy 州邢,該類的調(diào)用者有可能會(huì)忘記或者根本不知道“編譯器會(huì)自動(dòng)對(duì) block 進(jìn)行了 copy 操作”,他們有可能會(huì)在調(diào)用之前自行拷貝屬性值褪子。這種操作多余而低效量淌。
PS1: 這段話引自@iOS程序犭袁 的OGitHub - ChenYilong/iOSInterviewQuestions:...《招聘一個(gè)靠譜的iOS》面試題參考答案/《招聘一個(gè)靠譜的iOS》面試題參考答案(上).md
PS2: 蘋果官方建議。delegate一般用weak修飾嫌褪,這是為了防止內(nèi)存泄漏呀枢。比方說(shuō)一個(gè)viewController持有一個(gè)tableview,tableview的代理是這個(gè)viewController渔扎。如果用strong修飾delegate硫狞,就會(huì)造成循環(huán)引用。 ????
從xib或者storyboard上拖出來(lái)一個(gè)控件A晃痴,自動(dòng)就是weak修飾残吩。這是因?yàn)榭丶嗀放到xib上,已經(jīng)被xib上的view強(qiáng)引用了倘核。A的創(chuàng)建位置是在xib上泣侮,我們?cè)诼暶鲗傩缘奈恢檬且玫竭@個(gè)控件A的引用,用weak就可以了紧唱,不會(huì)增加引用計(jì)數(shù)活尊。 ??
OC寫方法的時(shí)候沒(méi)寫返回值類型[doge],編譯運(yùn)行通過(guò)漏益,默認(rèn)是id ????
OC向nil發(fā)消息不回崩潰