我试图div在其父级中心内联.父元素也有一个div浮动到右边的子元素.由于右对齐div,我的居中div向左移动.无论浮动的位置/大小如何,我都希望将中间div居中,如下图所示.

.parent {
text-align: center;
}
.parent div {
display: inline-block;
}Run Code Online (Sandbox Code Playgroud)
<div id="parent">
<div> ... </div>
<div style="float:right"> ... </div>
</div>Run Code Online (Sandbox Code Playgroud)
当前设置在父级内部都有内部div,但我假设正确的方法是将右对齐的div外部与绝对位置一起使用?
此外,我在同一页面上有多个父div实例.
我怎样才能达到这个效果?
根据介绍ObjectiveC文字的WWDC视频,NSMutableArray可以像这样初始化s:
[NSMutableArray arrayWithArray:@[]];
Run Code Online (Sandbox Code Playgroud)
但如果我们这样做会怎么样:
[@[] mutableCopy];
Run Code Online (Sandbox Code Playgroud)
我知道一个是初始化数组,另一个是提供浅拷贝; 因此内存管理是不同的.但是,如果我们使用ARC,使用后者有什么缺点?它更贵吗?ARC可能会以不同的方式处理,但我只是想知道使用mutableCopy是否更糟糕.
我正在创建一个包含xib文件的静态iOS框架(Xcode 6中的默认模板).
但是,在将我的框架添加到另一个应用程序时,我无法加载nib文件,我收到以下错误:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </private/var/mobile/Containers/Bundle/Application/89B7C8F1-698A-4E0B-AD8F-4DB414A6001B/Sample.app> (loaded)' with name 'MyNibName''
Run Code Online (Sandbox Code Playgroud)
我尝试了几种解决方案,其中一些在此概述.我仍然无法解决这个问题.
我看到很多对这个流行项目的引用现在都不受支持,因为xcode具有内置功能.我应该使用它吗?
在我的框架目标中,我将xib文件包含在"复制包资源"构建阶段,我在构建的框架目录中看到它们,但是,我注意到生成的框架结构不遵循apple文档中概述的结构.即使我更改了框架结构(使用版本并将文件夹Header和Resources文件夹链接到当前版本),我仍然无法解决问题.
我尝试通过以下方式加载我的笔尖:
1按框架名称加载bundle,nil在这种情况下是bundle
NSString *resourceBundlePath = [[NSBundle mainBundle] pathForResource:@"myframework" ofType:@"framework"];
resourcesBundle = [NSBundle bundleWithPath:resourceBundlePath];
self = [super initWithNibName:@"MyNibName" bundle:resourcesBundle];
Run Code Online (Sandbox Code Playgroud)
2创建资源包并将其添加到框架中.也是nil.请注意,如果我将捆绑包单独添加到项目中,则此解决方案有效,但这会破坏框架的用途.
NSString *resourceBundlePath = [[NSBundle mainBundle] pathForResource:@"resources" ofType:@"bundle"];
resourcesBundle = [NSBundle bundleWithPath:resourceBundlePath];
self = [super initWithNibName:@"MyNibName" bundle:resourcesBundle];
Run Code Online (Sandbox Code Playgroud)
3按类加载bundle仍然无法正常工作,但它返回的应用程序包与中的相同[NSBundle …
我试图添加几个顺序出现的标签,每个标签之间有一个时间延迟.标签将显示0或1,并且值是随机计算的.我正在运行以下代码:
for (int i = 0; i < 6; i++) {
NSString *cowryString;
int prob = arc4random()%10;
if (prob > 4) {
count++;
cowryString = @"1";
}
else {
cowryString = @"0";
}
[self runAction:[CCSequence actions:[CCDelayTime actionWithDuration:0.2] ,[CCCallFuncND actionWithTarget:self selector:@selector(cowryAppearWithString:data:) data:cowryString], nil]];
}
Run Code Online (Sandbox Code Playgroud)
使标签出现的方法是:
-(void)cowryAppearWithString:(id)sender data:(NSString *)string {
CCLabelTTF *clabel = [CCLabelTTF labelWithString:string fontName:@"arial" fontSize:70];
CGSize screenSize = [[CCDirector sharedDirector] winSize];
clabel.position = ccp(200.0+([cowries count]*50),screenSize.height/2);
id fadeIn = [CCFadeIn actionWithDuration:0.5];
[clabel runAction:fadeIn];
[cowries addObject:clabel];
[self addChild:clabel];
}
Run Code Online (Sandbox Code Playgroud)
此代码的问题在于所有标签在相同时刻出现并具有相同的延迟.我明白,如果我使用[CCDelayTime actionWithDuration:0.2*i] …
我正在设计一个自定义按钮,需要我覆盖一个UIButton顶部UIImageView.在UIImageView使用[UIImage stretchableImageWithLeftCapWidth:topCapHeight:]图像和UIButton具有带图案图像的背景颜色[UIColor colorWithPatternImage:[UIImage imageNamed:@"buttonPattern.png"]]
我面临的问题是,在iPhone 4上,虽然它们应该匹配,但来自UIButton和的图像UIImageView看起来颜色略有不同.在iPhone 3GS上测试相同的东西显示没有色差的正常结果.
此图像显示了差异:

你可以看到它在3GS上看起来很好.在视网膜显示屏上,您可以清楚地看到颜色的差异.我甚至尝试在视网膜显示器上使用低分辨率图像(来自3GS),颜色仍然显示不同.这是视网膜显示设备中的一个错误吗?以前有人遇到过这个问题吗?
键盘未出现在模拟器上的文本字段中.
创建了文本字段.
txt_UserName = new UITextField {
Placeholder = "Enter Username",
BorderStyle = UITextBorderStyle.RoundedRect,
Font = UIFont.FromName(Constants.KHELVETIC,Constants.KFontSize12),
VerticalAlignment = UIControlContentVerticalAlignment.Center,
AutocorrectionType = UITextAutocorrectionType.No,
AutocapitalizationType = UITextAutocapitalizationType.None,
ClearButtonMode = UITextFieldViewMode.WhileEditing,
LeftViewMode = UITextFieldViewMode.Always,
ReturnKeyType = UIReturnKeyType.Next,
BackgroundColor = UIColor.White,
ShouldReturn = delegate {
txt_Email.BecomeFirstResponder ();
return true;
}
};
txt_Email = new UITextField {
Placeholder = "Enter Email",
BorderStyle = UITextBorderStyle.RoundedRect,
Font = UIFont.FromName(Constants.KHELVETIC,Constants.KFontSize12),
VerticalAlignment = UIControlContentVerticalAlignment.Center,
AutocorrectionType = UITextAutocorrectionType.No,
AutocapitalizationType = UITextAutocapitalizationType.None,
ClearButtonMode = UITextFieldViewMode.WhileEditing,
KeyboardType = UIKeyboardType.EmailAddress,
LeftViewMode = …Run Code Online (Sandbox Code Playgroud) 我想知道调用[[MyClass alloc] init]已经存在的(已分配的)对象是否会在ARC中造成泄漏?或者它是否为您管理发布和重新分配?
会做更好的事情:
myObject = nil;
myObject = [[MyClass alloc] init];
Run Code Online (Sandbox Code Playgroud)
哪个更合适?还有另一种方法可以做到这一点吗?
我有一个包含嵌套NSArrays的NSArray.我正在寻找一种方法来根据嵌套数组的对象数按升序对父数组进行排序.所以如果[array1 count]是4,[array2 count]是2并且[array3 count]是9,我会得到:array2,array1,array3 ......
我的cocos2d游戏支持视网膜显示有问题.一切都习以为常,但现在我正在进行更新.在此更新中,我只添加了3个新图像(也在高清版本中).我使用的是用zwoptex制作的纹理图册.生成的png是gameart.png和gameart-hd.png.我正在使用以下代码加载文件:
CCSpriteFrameCache* frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];
[frameCache addSpriteFramesWithFile:@"gameart.plist"];
Run Code Online (Sandbox Code Playgroud)
当得到任何精灵我正在使用spriteWithFrameName:方法.以前一切都工作得很好(即使在iPhone 4上),但现在我只在iPhone 4上收到以下错误:
cocos2d: CCSpriteFrameCache: Frame 'tilei.png' not found
*** Assertion failure in -[BoardTile initWithSpriteFrame:]
Run Code Online (Sandbox Code Playgroud)
gameart.png和gameart-hd.png(tilei.png和tilei-hd.png)以及plist文件中都有文件tilei.我重新检查了一千次.怎么可能出错?请注意,错误未显示-hd后缀,即使它仅在iPhone 4上运行时出现.