在写入实例变量的时候,使用self.xx方式,通过其“设置方法”来设置;
而在读取实例变量的时候,使用_xx方式,此方法既能提高读取速度,又能保证相关属性的“内存管理语义”
为了防止阻塞主线程,造成页面卡顿,影响交互,我们会将耗时的任务放到其他线程,等任务结束时,再切换到主线程更新UI,所以代码中经常会涉及到线程的切换
—————————————————————————————————————
UIScrollView :
UIScrollView是UICollectionView和UITableView的父类.
contentSize:内容(content)的尺寸
contentInset:内容的padding,给内容四周加边距
contentOffset:当前scrollView的左上角相对于内容左上角的偏移offset
——————————————————————————————————————
香信中:
//Swift
dispatch_queue_t queue=dispatch_queue_create(“XXX”,nil);
dispatch_async(queue,^{
dispatch_async(dispatch_get_main_queue(),^{
<#code#>
});
});
//Objective-c
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0);
dispatch_async(queue,^{
//完成耗时任务
dispatch_async(dispatch_get_main_queue(),^{
//在主线程中更新UI
});
});
dispatch_sync 和 dispatch_async 函数 需要两个参数,一个是队列 queue,一个是需要添加的任务 block。它们的共同点是 block 都会在指定的队列 queue 上执行,无论 queue 是并行队列还是串行队列;不同的是 dispatch_sync 会阻塞当前线程,直到 block 结束,而 dispatch_async 不会阻塞当前线程。在做比较耗时的任务时,比如读取网络数据,就需要使用 dispatch_async 将任务异步的添加到另一个线程中处理。
香信中的枚举
{
FriendCircleType_Text, //相机图像
FriendCircleType_Photo, //相册
FriendCircleType_Share, //分享
FriendCircleType_Video, //視頻
FriendCircleType_Link //链接
};
//匿名枚举
typedef enum
{
iCarouselTypeLinear = 0,
iCarouselTypeRotary,
iCarouselTypeInvertedRotary,
iCarouselTypeCylinder,
iCarouselTypeInvertedCylinder,
iCarouselTypeCoverFlow,
iCarouselTypeCoverFlow2,
iCarouselTypeCustom
} iCarouselType;
//如果要赋值的话iCarouselType iCarousel = iCarouselTypeCustom;
typedef NS_ENUM(NSUInteger,MapType)
{
GoogleMap,
BaiduMap,
AMap,
QMap,
AppleMap
};
//有些框架中经常有NS_OPTIONS 就只是一种更现代的枚举方式而已
typedef NS_OPTIONS(NSUInteger,UIViewAutoresizing){ 二进制 十进制
UIViewAutoresizingNone = 0, 000000 0
UIViewAutoresizingFlexibleLeftMargin = 1 << 0, 000001 1
UIViewAutoresizingFlexibleWidth = 1 << 1, 000010 2
UIViewAutoresizingFlexibleRightMargin = 1 << 2, 000100 4
UIViewAutoresizingFlexibleTopMargin = 1 << 3, 001000 8
UIViewAutoresizingFlexibleHeight = 1 << 4,
UIViewAutoresizingFlexibleBottomMargin = 1 << 5
};
// <<为左移 在二进制中如图所示。然后可以通过二进制中的 按位或 按位与 亦或等 实现增加新技能 ,解除该技能外所有技能等操作
AttackType attackType = Melee | Fire;
// 二进制 十进制
// Melee 000001 1
// Fire 000010 2
// Melee | Fire 000011 3
Block中要修改外部变量的时候 要在外部变量前加上 __block
键盘通知
[super viewDidAppear:animated];
//建立通知 拿到键盘的高度
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShow:)name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillDisappear:)name:UIKeyboardWillHideNotification object:nil];
}
#pragma mark -------------------------通知事件
-(void)keyboardWillShow:(NSNotification *)noti
{
NSDictionary *info =[noti userInfo];
CGSize kbSize =[[info objectForKey:UIKeyboardFrameEndUserInfoKey]CGRectValue].size;
CGFloat height = [UIScreen mainScreen].bounds.size.height -(self.sureBtn.frame.origin.y + self.sureBtn.frame.size.height + 64 + 10);
int offset = kbSize.height - height ;
if(offset > 0)
{
NSTimeInterval animationDuration = 0.30f;
[UIView beginAnimations:@"moveUp" context:nil];
[UIView setAnimationDuration:animationDuration];
self.view.frame = CGRectMake(0,0 - offset,self.view.frame.size.width,self.view.frame.size.height);
[UIView commitAnimations];
}
}
-(void)keyboardWillDisappear:(NSNotification *)noti
{
NSTimeInterval animationDuration = 0.30f;
[UIView beginAnimations:@"ResizeForKeyboard" context:nil];
[UIView setAnimationDuration:animationDuration];
self.view.frame = CGRectMake(0,0,[UIScreen mainScreen].bounds.size.width,[UIScreen mainScreen].bounds.size.height);
[UIView commitAnimations];
}```