gpt4 book ai didi

ios - 为什么在 6.1 模拟器中没有显示自定义 drawRect?

转载 作者:可可西里 更新时间:2023-11-01 03:33:08 25 4
gpt4 key购买 nike

UICollectionViewCell 中有一个 UIView 子类 (ThumbView)。以下代码在 iOS 7 模拟器中运行良好:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"Cell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
ThumbView *thumbView = (ThumbView *)[cell viewWithTag:1];
[thumbView setNeedsDisplay];
return cell;
}

enter image description here

但是,在iOS 6版本的模拟器中:

网格都没有了:

enter image description here

我在 ThumbView 的 drawRect 中放置了一个 NSLog 以确保调用了 drawRect

怎么了?

  • Xcode 版本 5.0 (5A1412)
  • iOS 模拟器版本 7.0 (463.9.4)

更新(绘图代码):

- (void)drawRect:(CGRect)rect
{
NSLog(@"%s", __func__);
[self drawGrid:rect];
}

- (void)drawGrid:(CGRect)rect
{
CGFloat margin = self.margin;
CGFloat lineWidth = 2.0;

CGContextRef context = UIGraphicsGetCurrentContext();
CGRect gridRect = CGRectInset(rect, margin, margin);

for (NSInteger i = 1; i < 9; i++) {
CGFloat h = gridRect.size.height / 9;
CGFloat y = i * h;
CGContextMoveToPoint(context, margin, y+margin);
CGContextAddLineToPoint(context, gridRect.size.width+margin, y+margin);
CGContextSetLineWidth(context, lineWidth/4.0);
if (i == 3 || i == 6) {
CGContextSetStrokeColorWithColor(context, UIColor.darkGrayColor.CGColor);
} else {
CGContextSetStrokeColorWithColor(context, UIColor.lightGrayColor.CGColor);
}
CGContextStrokePath(context);
}

for (NSInteger i = 1; i < 9; i++) {
CGFloat w = gridRect.size.width / 9;
CGFloat x = i * w;
CGContextMoveToPoint(context, x+margin, margin);
CGContextAddLineToPoint(context, x+margin, gridRect.size.height+margin);
CGContextSetLineWidth(context, lineWidth/4.0);
if (i == 3 || i == 6) {
CGContextSetStrokeColorWithColor(context, UIColor.darkGrayColor.CGColor);
} else {
CGContextSetStrokeColorWithColor(context, UIColor.lightGrayColor.CGColor);
}
CGContextStrokePath(context);
}

CGFloat frameWidth = lineWidth * 2.0;
CGRect frameRect = CGRectInset(rect, 0.0, 0.0);
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) frameWidth = lineWidth * 2.0;
CGContextSetLineWidth(context, frameWidth);
CGContextSetStrokeColorWithColor(context, UIColor.darkGrayColor.CGColor);
CGContextStrokeRect(context, frameRect);
}

最佳答案

没有看到代码很难说。当我在 Retina 和非 Retina 模拟器上运行代码并且没有正确考虑比例差异时,我已经看到过这样的事情。

关于ios - 为什么在 6.1 模拟器中没有显示自定义 drawRect?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18842687/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com