在使用Apple LLVM编译器3.0并使用-O3编译时,我发现了一个与NSCoder不同的错误.它只会在设备上崩溃.我测试了运行iOS 5的iPhone 4,运行iOS 5的iPad 2和运行iOS 4的iPad 1.所有都崩溃了.这是相关的代码部分:
-(id)initWithCoder:(NSCoder*)decoder
{
if (![super init])
{
return nil;
}
NSUInteger length = 0;
uint8_t* data = (uint8_t*)[decoder decodeBytesForKey:BBKey returnedLength:&length];
m_value = *(BBPointI32*)data;
return self;
}
Run Code Online (Sandbox Code Playgroud)
这就是BBPointI32:
typedef struct
{
NSInteger x;
NSInteger y;
}
BBPointI32;
Run Code Online (Sandbox Code Playgroud)
取消引用EXC_BAD_ACCESS时会发生这种情况data.这不是空指针问题.如果我附加GDB,我可以看到长度是8,sizeof(BBPointI)也是8,数据是正确的.
如果我查看反汇编,崩溃就发生在:
ldrd r2, r3, [r0]
Run Code Online (Sandbox Code Playgroud)
看起来不错.r0包含0xb546e,这是地址data.当我检查那个内存时,我可以看到它包含我期望的数据.对于任何感兴趣的人,r2包含72(不确定是什么),r3包含8(最可能是值length).
任何人都可以对这个问题有所了解吗?
我使用以下方法加载此(非常小)的图像:
UIImage* image = [UIImage named:@"someFile.png"];
Run Code Online (Sandbox Code Playgroud)
图像为4x1,按顺序从左到右包含红色,绿色,蓝色和白色像素.
接下来,我从底层CGImage中获取像素数据:
NSData* data = (NSData*)CGDataProviderCopyData(CGImageGetDataProvider(image.CGImage));
Run Code Online (Sandbox Code Playgroud)
现在,出于某种原因,像素数据的布局取决于iOS设备.
当我在模拟器或iPhone 4上运行应用程序时,像素数据如下所示:
(255,0,0),(0,255,0),(0,0,255),(255,255,255)
因此,像素为每像素3个字节,蓝色为最高有效字节,红色为最低有效字节.所以我想你称之为BGR?
当我检查CGBitmapInfo时,我可以看到kCGBitmapByteOrderMask是kCGBitmapByteOrderDefault.我无法找到解释"默认"的地方.
另一方面,当我在我的第一代iPhone上运行时,像素数据如下所示:
(0,0,255,255),(0,255,0,255),(255,0,0,255),(255255255255)
因此每个通道4个字节,alpha作为最重要的字节,蓝色作为最不重要的字节.所以......这叫做ARGB?
我一直在查看CGBitmapInfo,了解如何检测布局的线索.在第一代iPhone上,kCGBitmapAlphaInfoMask是kCGImageAlphaNoneSkipFirst.这意味着忽略了最重要的位.这是有道理的.在第一代iPhone上,kCGBitmapByteOrderMask是kCGBitmapByteOrder32Little.我不知道这意味着什么或如何将它与R,G和B组件如何在内存中布局相关联.任何人都可以对此有所了解吗?
谢谢.
我有一个简单的应用程序,其中肖像UINavigationController呈现景观UINavigationController.通常它工作正常.有时,横向视图控制器以纵向显示,但具有横向边界.
以下是它的工作原理:为了限制导航控制器的方向,我有一个类,OrientableNavigationController它派生自UINavigationController并公开了特定于旋转的属性:
class OrientableNavigationController: UINavigationController {
private var _supportedInterfaceOrientations: UIInterfaceOrientationMask = .all
private var _shouldAutorotate: Bool = false
private var _preferredInterfaceOrientationForPresentation: UIInterfaceOrientation = .portrait
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
get { return _supportedInterfaceOrientations }
set { _supportedInterfaceOrientations = newValue }
}
override var shouldAutorotate: Bool {
get { return _shouldAutorotate }
set { _shouldAutorotate = newValue }
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
get { return _preferredInterfaceOrientationForPresentation }
set { _preferredInterfaceOrientationForPresentation = …Run Code Online (Sandbox Code Playgroud)