我使用 Grand Central Dispatch 方法在队列中执行我的应用程序。我在该队列的计算中决定按钮的框架。我希望我的应用程序重新绘制其屏幕并计算旋转后的新帧。这是我所做的一些伪代码解释:
CGFloat a=123, b=24;
dispatch_async(drawingQue, ^{
//needed loops to get the total button count-how many ones will be drawn et..
for(int x=0;x<someCount<x++){
for(int y=0;y<anotherCount;y++){
//needed frame&name ect assingments
button.frame= CGRectMake(x+y, x-y, a, b);
[button setTitle:@"abc"];}}
};
我想要的是,我如何给这个块命名并在
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
}
委托方法?例如,如果旋转是横向的,我想使用a=234
而不是 123.. 请帮忙。提前致谢..
声明块类型的实例变量并使用Block_copy
保留块:
@interface My {
void (^myBlock)(void);
}
@end
myBlock = Block_copy(^{
...block code...
});
// later call it
myBlock();
// don't forget to release it in dealloc
重要的是要copy将块存储在其文字范围之外之前(^{...}
),因为原始块存储在堆栈上,并且当作用域退出时就会死亡。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)