2018.12.12 -2019.1.25项目笔记总结

1、masksToBounds 

圆角cornerRadius 现在与masksToBounds无关了

2、https://m.cnbeta.com/view/773867.htm

苹果的新表情

3、**说业务逻辑尽量写在viewModel,里面***ModelArr ,不要写在vc,有他的道理,但是我觉得不行啊,但实际我的处理逻辑不是那么简单。

4、imageView.layer.shadowColor = [UIColor redColor].CGColor;

imageView.layer.shadowOffset = CGSizeMake(0, 0);

imageView.layer.shadowOpacity = 0.1;//不透明度

imageView.layer.shadowRadius = 15;//阴影的半径

关于约束的几个属性

shadowOpacity不透明度,是阴影的透明度的问题,

怎么理解这个imageView.layer.shadowRadius,半径是理解为去掉中间的方形,剩余的椭圆的半径

4、isDescendantOfView

判断这个是不是子视图

5、[self.collectionView scrollToItemAtIndexPath:indexPath

                                    atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally

                                            animated:YES];

滑动居中的代码

6、

__block CGFloat itemTotalWidth = 0;

///声明weak

      [self.tabArray enumerateObjectsUsingBlock:^(LVMDiscoverTabsModel * _Nonnull infoItem, NSUInteger idx, BOOL * _Nonnull stop) {

        CGFloat strWidth = [self calcItemWidth:infoItem];

        itemTotalWidth += strWidth;

    }];

只有修改值才加__block

5、instruments 工具的alloc稳步增加,是因为缓存,存疑。

6、莫名出现方法不识别,明明这个方法存在,但是就是提醒,使用了关机、关手机,文件重加,都不行,后面用shift + command + k 和fonder解决了。

7、通过删除一些模拟器,xcode 存量大大减轻

8、采搜狗的加号解决了键盘加号偏下的问题

9、     

BOOL boolValue = [model.yangimageurl isEmpty];

model.yangimageurl 

- (BOOL)isEmpty

{

    return (self == nil || [self length] == 0 || [self isEqualToString:@""]);

}

这个方法对于判断非空是有问题的,如果判断的对象为nil,根本不会走这个方法,应该用fudata里面的方法,更简单

10、UIButton (EnlargeTouchArea)

@interface UIButton(EnlargeTouchArea)

@end

扩大点击区域方法

11、核心bug是怎么解决的

现象:

(1)有很多问题

(2)四张图和八张图以及有空白

(3)一张图有空白

(4)空白的问题我居然没有考虑到hidden问题

(5)通过不断的log找到的

12、第一次重新赋值都要修复,因为对于新创建的cell updateConstraints方法是最后走的

 if (self.model.nnnn && ![self.model.nnnn empty]) {

     self.nameLabelTopDistanceLayout = [self.nameLabel autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:25.5];

 }else{

     self.nameLabelTopDistanceLayout = [self.nameLabel autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:31.];

   }

实际,不加也行,为什么呢,因为你在self.nameLabelTopDistanceLayout里面没有改self.nameLabelTopDistanceLayout值,setData里面的设置约束是最后一个。

所以,updateContraint里面要么要设置对,要么不设,因为有的很多时间只会走一次。如果设置错了就会有问题,没机会改了。

13、**说 ,代理要把self带出来,存疑

14、加了- (void)prepareForReuse {

    [super prepareForReuse];

    [self.view clearImageView];

}

其实没卵用

15、purelayout约束学习

autoCenterInSuperview

自动设置视图居中

以后也要常用relation东西,没怎么用过

16、

重用视图不加也行

为什么可以,因为把所有约束去掉了,剩余的视图虽然没有隐藏,但是约束没有了也就正常,因为没设约束,就可能出现大图问题

17、UIImageView *likeImageView = [[UIImageView alloc] initForAutoLayout];

    [self.backRightBottomView addSubview:likeImageView];

    likeImageView.image = [UIImage imageNamed:@“yang“];

    self.likeImageView = likeImageView;

    likeImageView.userInteractionEnabled = YES;

    [self.likeImageView addGestureRecognizer:tapGesture];

 [self.likeImageView addGestureRecognizer:tapGesture];

这句话去掉效果为什么会更好

手势只能加到一个视图上,不能加到多个,算这样后一个,如果你想让多个视图掉一个方法,需要添加多个手势

18、如果点击了按钮,你又不想切换选中状态,你就用代码立即切换过来

19、接口的调试以及bug的调试,义务的不熟悉,会很耗时间的,出了产品的问题,不要自己吞了,要写邮件告知,责任重大啊。

20、就如weakiself

@protocol 也可以点击protocol获得结果

输入re能引导出

#pragma clang diagnostic push

#pragma clang diagnostic ignored "-W<#warning-name#>"

        <#code#>

#pragma clang diagnostic pop

21、- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

    return [self getHeadView];

}

和headView

不是一回事,headView是会跟着滑动的,但是viewForHeader却不是,它会浮在下面。

22、

娱乐活动只能听歌、散步,睡觉,电脑听歌,节省电。

23、注册headView和cell都不一样

 [collectionView registerClass:[****cell class] forCellWithReuseIdentifier:@"kCollectionViewCell"];

 [collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"resusedId"];

使用:

UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"kCollectionViewCell" forIndexPath:indexPath];

resusedView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"resusedId" forIndexPath:indexPath];

重用的头forSupplementaryViewOfKind不能少

24、命名一定要规范,为什么呢,节省时间。很多提交和命名过后我都不知道什么意思。

我把uicollectionViewCell命名为YangCollectionViewCell时,出现那个重复文件的问题,不知道哪里出问题了。

但是把文件改为LVMCollectionViewCell,就好了。

25、 layout.sectionInset = UIEdgeInsetsMake(10, 10, 0, 10);

     layout.headerHeight = 0;

     layout.footerHeight = 0;

     layout.minimumColumnSpacing = 10;

     layout.minimumInteritemSpacing = 10;

上面是瀑布流流水约束,会形成一个中间和两边是10的间距。

 flowLayout.headerReferenceSize = CGSizeMake(kscreenwidth, 30);

    flowLayout.footerReferenceSize = CGSizeMake(0, 0);

    flowLayout.minimumLineSpacing = 10;

    flowLayout.minimumInteritemSpacing = 10;

    flowLayout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);

这个流水布局的中间是20 ,两边是10 。

26、 [self.nameLabel sizeToFit];

这个要慎用,这个设置后,虽然视图已经有了一个frame,但我们可以随意改变长度和宽度,不会有什么问题。但是我么针对一个宽度和高度设置了一个值时,如果我们没有去掉,重新去设置,可能既有问题。

27、当我们王文本里面插入\n换行符时,在空间够的情况下,会自动换行的,当我们设置numberLines > 0时间,换行的包括在里面。numberLines = 0意思是我不设置你换多少行,多少都行。此外,有了换行符,那个系统计算高度的方法也会将这些考虑在内。

28、记得巧妙的打log,打log帮我定位了UI错位和小手机瀑布流错乱的问题位置。巧妙log设置,很棒的,可以理解程序明面的走法。

29、h5加了一个接口,刚开始调试的时候不行,过一阵子,那个接口就能用了,原因,可能是那个接口需要一段时间才会上线。

30、h5 接口问题到最后才去做,这个问题很严重,人家要是上线了,就不帮你改了,凡事要有主次,以及耐心,好好调试。

31、可以在这里

- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(nonnull UICollectionViewCell *)cell forItemAtIndexPath:(nonnull NSIndexPath *)indexPath 「

}

做预加载,我之前是写在

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(nonnull NSIndexPath *)indexPath 

做预加载

其实这两个方法,都行,后一个方法还走在前面。最终结婚,预加载还是得写得display方法里面

32、微信都不支持ios5了,支持9,淘宝、京东都还是支持iOS8的,估计咱们还得继续支持吧。

33、再刷新的时候,各个按钮文件都要重新赋值,“我只是改一下numberlines值,无需更新ui”,这种想法是不对的。

34、虽然item和row在功能上是一致的, 但是从编码风格上来说, 并且结合上下文环境来说, tableview中一般使用row会更好些, collectionview中一般使用item会更好些。Thus the two are functionally identical.

35、 *****ViewCell *lastCell = (*****ViewCell *)[self.collectionView cellForItemAtIndexPath:lastIndexPath];

传值为nil这个问题要研究一下

36、当cell数量少,出现cell的时候,可能并不一定走这个方法

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

{

}

12 次到了右侧,右侧显示5个,按理说左滑的时候要打印其次,但是没有打印,只打印了三次,这可能是左边的七个里面被复用的只有三个,其他四个还在所有不用调用按个创建的方法

但是这个方法

collectionView:(UICollectionView *)collectionView willDisplayCell:(nonnull UICollectionViewCell *)cell forItemAtIndexPath

是真的出现在屏幕就会调用的。

这个解释上面的预加载。

37、轮播控件的核心原理是在合适的时候,设置contentoffset值,具体来说,是contentoffset.x的值只比contentsize.width少一个cellwith时,说明到了末端,回到起点。

数据源要首尾各加一个数据,首位加last,末位加first,将原先的数据扩展,就是一个轮播的数据源。滑动和轮播还是有点不一样的,滑动的距离有大有小,轮播是一页一页的,距离是cellWidth的整数倍

38、viewModel的精华是将一个vc的所有业务逻辑都写在一个viewModel里面去

第二次笔记:

1、我将艺术的布局拿过来,解决了indexPath item原来不是递增的问题,其实indexpath.item 和 indexPath.row是一样的

2、在setData里重新设置了图片的高度,解决高度问题。

3、用sectionInset 起来设定左右边界的高度。

CHTCollectionViewWaterfallLayout中间的思考问题:

4、minimumColumnSpacing 和 minimumInteritemSpacing的区别

而minimumInteritemSpacing是设置cell之间,包括上下间距,不包括左右间距,左右间距是由minimumColumnSpacing来设置。

5、是不是因为改了CHTCollectionViewWaterfallLayout里面数据使得indexPath.item递增???

6、我为什么这么紧张

我不知道哪里出问题了,还有就是生病了

7、CHTCollectionViewWaterfallLayout 一进来就会将所有的indexpath 的size都创建好吗?

8、创建以后就不会再用获取size的方法,以后到了对应的indexPath时,会拿到相应的cell,size 与indexPath对应。

9、既然size是与indexpath对应,那为什么UI拿的是错误的布局????

10、复用的时候为什么调用 [self.contentView setNeedsUpdateConstraints],方法不会调用updateConstraints方法了,我只能在setData里面进行重新布局,以前艺术的就是写在updateConstraints里面重新布局的,为什么呢????

这套机制跟UITableViewcell的区别

UITableView是能用的,每次重用的高度都要重新调用。

我改了一下为:

[self setNeedsUpdateConstraints];

[self updateConstraintsIfNeeded];

现在走了,之前的

[self.contentView setNeedsUpdateConstraints];

[self.contentView updateConstraintsIfNeeded];

不走

原因:

我们只是将视图加在contentview上面,但是那些视图根本不是contentview的属性,它是self的属性,所以只能调用self才会走方法updateConstraints 

(1)- (void)setNeedsUpdateConstraints;

When a property of your custom view changes in a way that would impact constraints, you can call this method to indicate that the constraints need to be updated at some point in the future. The system will then call updateConstraints as part of its normal layout pass. Use this as an optimization tool to batch constraint changes. Updating constraints all at once just before they are needed ensures that you don’t needlessly recalculate constraints when multiple changes are made to your view in between layout passes.

batch 分批处理

recalculate 重新计算

layout passes 布局通道

当你定制的视图的一个属性以某种方式改变了,那会影响约束,你能调用这个方法来显示约束需要在某个时间点更新,系统将会调用updateConstraints,把之前的变动作为正常布局的一部分,用这个方法作为一个优化工具重新计算约束改变。在他们需要更新前一次性更新约束确保你不需要做很多约束计算,当大量的改变在你的视图时。

(2)needsUpdateConstraints

A Boolean value that determines whether the view’s constraints need updating.

(3)updateConstraints

Override this method to optimize changes to your constraints.

(4)updateConstraintsIfNeeded

Updates the constraints for the receiving view and its subviews.

Whenever a new layout pass is triggered(触发引爆) for a view, the system invokes this method to ensure that any constraints for the view and its subviews are updated with information from the current view hierarchy and its constraints. This method is called automatically by the system, but may be invoked manually if 

you need to examine the most up to date constraints.(检查最新的约束)

(5)didUpdateContraint 约束的时候为什么要设置 didUpdateContraint这个键

因为如果不设置,会重复设置,而之前的约束又没有删除,导致可能出问题

(6) updateConstraintsIfNeeded

涉及到子视图,所有它的受体填self 和self.contentView都行

(7)就跟新逻辑而言,填self和self.conventView都行 但是要调用updateConstraints方法的话,只能用updateConstraints对应的对象

(8)

Important

Call [super updateConstraints] as the final step in your implementation.

(9)

结论:

A调用 setNeedsUpdateConstraints方法,必走A的updateConstraints方法

A调用 updateConstraintsIfNeeded方法,不走A的updateConstraints方法

约束更新,最好写在setData 方法里面

然后调用setNeedsUpdateConstraints ,和 updateConstraintsIfNeeded方法

在setData如果赋值新值

 self.yyAnimatedImageViewHeightConstraint.constant = [self calcuHeightFromImageSize:size]; 

 [self setNeedsUpdateConstraints]; 1

[self updateConstraintsIfNeeded]; 2

1和2两个方法只有随意写一个就行了

如果你不调用 setNeedsUpdateConstraints这个方法

(10)updateConstraints

这个方法的调用,还是需要调用 

[self.contentView updateConstraintsIfNeeded];

    [self.contentView setNeedsUpdateConstraints];

如果这个不写,updateConstraints不会走

结论:

首次的时候

 [self.contentView updateConstraintsIfNeeded];

 [self.contentView setNeedsUpdateConstraints];

[self updateConstraintsIfNeeded];

[self setNeedsUpdateConstraints];

这两个方法任意一个调用,都会调用updateConstraints方法

往后参考上面逻辑

didUpdateContraint 其实不要也行 

11、 以前:[self.nameLabel sizeToFit];

        [self.nameLabel autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:36 * kMDFScreenAutoLayoutScale];

        [self.nameLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:12 * kMDFScreenAutoLayoutScale];

        [self.nameLabel autoPinEdge:ALEdgeRight toEdge:ALEdgeLeft ofView:self.likeImageView withOffset:-10.f * kMDFScreenAutoLayoutScale];

        self.nameLabel.numberOfLines = 0;

        self.didUpdateContraint = YES;

后面

[self.nameLabel sizeToFit];

    self.nameLabel.numberOfLines = 0;

    [self.nameLabel autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:36 * kMDFScreenAutoLayoutScale];

    [self.nameLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:12 * kMDFScreenAutoLayoutScale];

    [self.nameLabel autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:47.5 * kMDFScreenAutoLayoutScale];

    self.nameLabel.numberOfLines = 0;

从项目里面去搜索代码

为什么h会出现异常,这其实是一个错误,冲突。系统爆出来了,你不知道而已。

sizeFIze其实就已经把长宽设置好了

疑问:

设定了sizeFit ,然后又设置了左右下面,numline ,

既然设置了sizeToFit 也就有了宽高,然后设置左右的话,会不会冲突呢,

猜想:sizefit设置的事软性约束,不是严格意义的

以后验证的吧,元旦验证 

12、 UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];

    view1.backgroundColor = [UIColor yellowColor];

    [self.view addSubview:view1];

    [view1 addSubview:self.bottomLine];

    self.bottomLine.frame = CGRectMake(0, 20, 100, 20);

    UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(100, 250, 100, 100)];

    view2.backgroundColor = [UIColor blackColor];

    [self.view addSubview:view2];

    [view2 addSubview:self.bottomLine];

最后显示成这样,很奇怪

结论:最后一个addSubview才是self.bottomLine的归属

我的想法

1、我以为UI错乱是因为复用了一个cell,继承的是别人的cell的frame,当我以为是那样的时候,我的心啊,很紧张

关键步骤,通过特定的indexpath = 12来计算判断,打印cell获取frame结果烟消云散。

- (void)updateConstraintsIfNeeded NS_AVAILABLE_IOS(6_0); // Updates the constraints from the bottom up for the view hierarchy rooted at the receiver. UIWindow's implementation creates a layout engine if necessary first.

- (void)updateConstraints NS_AVAILABLE_IOS(6_0); // Override this to adjust your special constraints during a constraints update pass

- (BOOL)needsUpdateConstraints NS_AVAILABLE_IOS(6_0);

- (void)setNeedsUpdateConstraints NS_AVAILABLE_IOS(6_0);

一定会走updateContrait方法的

13、对于一个可能出现又可能不出现的视图,我们在cell里面先隐藏起来,然后显示出来

第二次记录:这里可以设置指定target搜索

14、Aspect Ratio 用法
设置视图的宽高比

使用场景:
视图宽度随着屏幕宽度变化拉伸时,让其高度自动进行等比例拉伸.保持该视图宽高比不变.

猜你喜欢

转载自blog.csdn.net/u014544346/article/details/86721697
今日推荐