我有点失落.我已经使用UIView的图层属性来围绕我的应用程序中的多个元素的角落.但是,这一个UIImageView根本就不符合.不确定我错过了什么.
UIImageView(称为previewImage)包含在表视图单元格中.我已经尝试将cornerRadius属性设置为多个位置(在单元格本身和创建单元格的控制器中)无济于事.
static NSString *CellIdentifier = @"MyTableViewCell";
MyTableViewCell *cell = (MyTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:CellIdentifier owner:self options:nil];
cell = [topLevelObjects objectAtIndex:0];
cell.previewImage.layer.cornerRadius = 20; //Made it 20 to make sure it's obvious.
}
Run Code Online (Sandbox Code Playgroud)
有没有关于细胞加载的方式,我错过了?
很难跟踪iPad应用程序中的崩溃.这个困难的真正原因是当应用程序失败时没有错误或堆栈跟踪.它就像Keiser Soze一样消失,"就像那样,噗.他走了."
我已经在模拟器和设备上复制了崩溃.设备日志为零,控制台中没有任何内容,等等.
我知道在崩溃期间,一些CoreGraphics
操作正在后台线程中发生.通常,三个左右的NSOperations正在踢一些图像混合.
混合包含CGContext*调用(DrawImage,SetBlendMode,SetAlpha等).NSOperation回调主线程中的委托来处理图像并将其设置为UIImage
,因此它不应该是UI主线程冲突,但此时我不打算任何折扣.
我是否缺少一些Xcode技巧来追踪究竟发生了什么?或者至少可以更好地了解问题所在?
编辑我已经在仪器中运行应用程序跟踪内存使用情况,看到它在2MB左右稳定稳定.所以,不要认为这是一个记忆问题.但经过考虑,这块岩石稳定2MB似乎异常低落.有没有机会仪器没有获得CoreGraphics分配?
我的一个单元测试失败了,原因是我没有预料到.似乎是一个调用isKindOfClass
返回NO,但是当我调试并逐步执行时,它似乎没有理由.
代码是:
if ([self.detailItem isKindOfClass:[MovieInfo class]]) {
[self configureViewForMovie];
}
Run Code Online (Sandbox Code Playgroud)
我逐步完成了代码并做了:
po self.detailItem
Run Code Online (Sandbox Code Playgroud)
显示:
(id) $1 = 0x0ea8f390 <MovieInfo: 0xea8f390>
Run Code Online (Sandbox Code Playgroud)
那么,我错过了什么,为什么在这种情况下if语句会返回false?
编辑:
这是DetailItem的setter:
- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
NSLog(@"%@", [newDetailItem class]);
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
if (self.masterPopoverController != nil) {
[self.masterPopoverController dismissPopoverAnimated:YES];
}
}
Run Code Online (Sandbox Code Playgroud)
它是Master Detail模板的模板代码.
单元测试在setUp中创建一个MovieInfo:
movie = [[MovieInfo alloc] initWithMovieName:@"Movie" movieID:1];
Run Code Online (Sandbox Code Playgroud)
并在测试中设置它
controller.detailItem = movie;
Run Code Online (Sandbox Code Playgroud)
另外,我添加了一个参数断言setDetailItem
:
NSParameterAssert([newDetailItem isKindOfClass:[MovieInfo class]] || [newDetailItem isKindOfClass:[PersonInfo class]] || newDetailItem …
Run Code Online (Sandbox Code Playgroud) 我有一个UISlider
视图的一部分加载到UIScrollView
启用分页.我注意到了一个意想不到的行为.如果用户尝试快速使用滑块(即按下并移动),它会"激活"滚动视图,从而导致页面切换.但是,如果按住一秒钟滑块"激活",则可以调整滑块值.这种行为是不可取的.
UISlider
加载到响应中时,响应的最佳方法是UIScrollView
什么?我已经考虑添加一个"阻止"视图,只是吃掉滑块下面的触摸事件,但不确定这是否是最好的方法.
我在这里撞墙,我很确定我做的是蠢事,所以有时间把我的愚蠢公之于众.
我正在尝试拍摄两张图像,使用标准混合算法(Hardlight,softlight,overlay,multiply等)将它们混合成第三张图像.
因为Android没有内置这样的混合属性,所以我已经走下了获取每个像素并使用算法组合它们的道路.但是,结果是垃圾.下面是简单乘法混合的结果(使用的图像和预期结果).
基础:
混合:
预期结果:
垃圾结果:
任何帮助,将不胜感激.下面是代码,我试图删除所有"垃圾",但有些可能已经完成了.如果事情不清楚,我会清理它.
ImageView imageView = (ImageView) findViewById(R.id.ImageView01);
Bitmap base = BitmapFactory.decodeResource(getResources(), R.drawable.base);
Bitmap result = base.copy(Bitmap.Config.RGB_565, true);
Bitmap blend = BitmapFactory.decodeResource(getResources(), R.drawable.blend);
IntBuffer buffBase = IntBuffer.allocate(base.getWidth() * base.getHeight());
base.copyPixelsToBuffer(buffBase);
buffBase.rewind();
IntBuffer buffBlend = IntBuffer.allocate(blend.getWidth() * blend.getHeight());
blend.copyPixelsToBuffer(buffBlend);
buffBlend.rewind();
IntBuffer buffOut = IntBuffer.allocate(base.getWidth() * base.getHeight());
buffOut.rewind();
while (buffOut.position() < buffOut.limit()) {
int filterInt = buffBlend.get();
int srcInt = buffBase.get();
int redValueFilter = Color.red(filterInt);
int greenValueFilter = Color.green(filterInt);
int blueValueFilter = Color.blue(filterInt);
int redValueSrc = Color.red(srcInt); …
Run Code Online (Sandbox Code Playgroud) 我已经阅读了一些片段,提到你不应该在init或dealloc方法中使用dot-notation.但是,我似乎永远无法找出原因.一篇文章顺便提到它与KVO有关,但没有更多.
@interface MyClass : NSObject {
SomeObject *object_;
}
@property (nonatomic, retain) SomeObject *object;
@end
Run Code Online (Sandbox Code Playgroud)
这个实现不好?
@implementation MyClass
@synthesize object = object_;
- (id)initWithObject:(SomeObject *)object {
if (self = [super init]) {
self.object = object;
}
return self;
}
@end
Run Code Online (Sandbox Code Playgroud)
但这很好吗?
@implementation MyClass
@synthesize object = object_;
- (id)initWithObject:(SomeObject *)object {
if (self = [super init]) {
object_ = [object retain];
}
return self;
}
@end
Run Code Online (Sandbox Code Playgroud)
在init中使用点符号有哪些缺陷?
我最近通过AirPrint介绍了Printing,但是不想放弃对4.2版本的支持(显然).以前做过像Game Center这样的事情.在这种情况下,我发现特别奇怪的是我必须弱连接UIKit.打印不包含在自己的框架中,使我更精细.
这只是感觉不对,虽然它解决了我的问题,允许应用程序在所有版本上正常运行.
在Apple的SDK兼容性指南中,他们指出:
使用部署目标中可用的框架时,您应该要求该框架(而不是弱链接).
UIKit中是可用的,只是不类,如UIPrintInfo
,UIPrintInteractionController
等.
我是对的,弱连接这样一个核心框架似乎很奇怪吗?有没有更好的办法?
我遇到了一个非常奇怪,令人沮丧的问题。最初以纵向加载我的视图时,安全区域布局指南为预期大小。但是,旋转到横向然后返回到纵向后,它们与初始负载不同。这抛弃了iPhone X上的所有子视图。
我添加了打印语句 viewWillLayoutSubviews()
print("View Size: \(view.frame.size)")
print("View Layout Size: \(view.safeAreaLayoutGuide.layoutFrame.size)")
Run Code Online (Sandbox Code Playgroud)
运行应用程序并执行方向更改时,输出为:
更改方向之前:
View Size: (375.0, 812.0)
View Layout Size: (375.0, 734.0)
Run Code Online (Sandbox Code Playgroud)
景观:
View Size: (812.0, 375.0)
View Layout Size: (724.0, 354.0)
Run Code Online (Sandbox Code Playgroud)
返回肖像:
View Size: (375.0, 812.0)
View Layout Size: (383.0, 734.0)
Run Code Online (Sandbox Code Playgroud)
如您所见,视图大小没有变化。但是,布局指南的尺寸要宽8 像素。
任何帮助将不胜感激。
我正在尝试在两个图像上应用混合滤镜(在本例中为HardLight).基础Android库不支持HardLight,因此,我在每个像素上手动完成.第一次运行正在运行,但速度低于恒星.从基础500x500图像和500x500过滤器生成500x500图像的过程太长了.这段代码也用于生成缩略图(72x72),它与应用程序的核心不可分割.我喜欢一些关于如何提高速度的建议和/或提示.
如果假设两个图像都不具有alpha,那么可以获得巨大的收益,这很好.注意:BlendMode和alpha是示例中未使用的值(BlendMode将选择混合类型,在本例中为硬编码HardLight).
public Bitmap blendedBitmap(Bitmap source, Bitmap layer, BlendMode blendMode, float alpha) {
Bitmap base = source.copy(Config.ARGB_8888, true);
Bitmap blend = layer.copy(Config.ARGB_8888, false);
IntBuffer buffBase = IntBuffer.allocate(base.getWidth() * base.getHeight());
base.copyPixelsToBuffer(buffBase);
buffBase.rewind();
IntBuffer buffBlend = IntBuffer.allocate(blend.getWidth() * blend.getHeight());
blend.copyPixelsToBuffer(buffBlend);
buffBlend.rewind();
IntBuffer buffOut = IntBuffer.allocate(base.getWidth() * base.getHeight());
buffOut.rewind();
while (buffOut.position() < buffOut.limit()) {
int filterInt = buffBlend.get();
int srcInt = buffBase.get();
int redValueFilter = Color.red(filterInt);
int greenValueFilter = Color.green(filterInt);
int blueValueFilter = Color.blue(filterInt);
int redValueSrc = Color.red(srcInt);
int greenValueSrc = …
Run Code Online (Sandbox Code Playgroud) 我们的应用程序已经实施了 ApplePay 多年。就在最近,我按下按钮触发它,只发现付款表PKPaymentAuthorizationViewController
没有出现。它不会在沙箱(即连接到 Xcode 的模拟器或设备)环境中滑动,但放置断点表明它已成功创建。自从我测试这个已经有一段时间了,但我怀疑 Xcode11 或 iOS 13 会发生一些变化。
我的代码是非常标准的 Apple Pay,但贴在下面。
let item = PKPaymentSummaryItem()
item.label = "Our Label"
let price = NSDecimalNumber(mantissa: UInt64(totalPrice), exponent: -2, isNegative: false)
item.amount = price
items.append(item)
request.paymentSummaryItems = items
if let applePayController = PKPaymentAuthorizationViewController(paymentRequest: request) {
applePayController.delegate = self
present(applePayController, animated: true)
}
Run Code Online (Sandbox Code Playgroud) ios ×4
iphone ×3
android ×2
objective-c ×2
swift ×2
applepay ×1
autolayout ×1
bitmap ×1
blending ×1
cocoa ×1
crash ×1
debugging ×1
orientation ×1
syntax ×1
uiimageview ×1
uiscrollview ×1
uislider ×1
weak-linking ×1
xcode ×1