根据Collection View编程指南,应该处理单元格高光的视觉状态UICollectionViewDelegate.像这样:
- (void)collectionView:(PSUICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath
{
MYCollectionViewCell *cell = (MYCollectionViewCell*)[collectionView cellForItemAtIndexPath:indexPath];
[cell highlight];
}
- (void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath
{
MYCollectionViewCell *cell = (MYCollectionViewCell*)[collectionView cellForItemAtIndexPath:indexPath];
[cell unhighlight];
}
Run Code Online (Sandbox Code Playgroud)
我不喜欢这种方法的是它为委托添加了非常特定于单元格的逻辑.事实上,UICollectionViewCell通过highlighted财产独立管理其突出显示的状态.
那么,压倒一切setHighlighted:不是一个更清洁的解决方案吗?
- (void)setHighlighted:(BOOL)highlighted
{
[super setHighlighted:highlighted];
if (highlighted) {
[self highlight];
} else {
[self unhighlight];
}
}
Run Code Online (Sandbox Code Playgroud)
这种方法有没有缺点而不是委托方法?
考虑一个视图控制器,当单击按钮时需要滑出(或隐藏)状态栏.
- (void) buttonClick:(id)sender
{
[[UIApplication sharedApplication] setStatusBarHidden:YES
withAnimation:UIStatusBarAnimationSlide];
}
Run Code Online (Sandbox Code Playgroud)
上面有效地隐藏了状态栏,但没有适当调整根视图的大小,在顶部留下20像素的间隙.
我期望的是根视图扩展到以前状态栏使用的空间(动画,持续时间与状态栏动画相同).
这样做的正确方法是什么?
(我知道有很多类似的问题,但我找不到任何关于按需隐藏状态栏而不是隐藏它以显示新的视图控制器)
显然,以下作品......
[[UIApplication sharedApplication] setStatusBarHidden:YES
withAnimation:UIStatusBarAnimationSlide];
[UIView animateWithDuration:0.25 animations:^{
CGRect frame = self.view.frame;
frame.origin.y -= 20;
frame.size.height += 20;
self.view.frame = frame;
}];
Run Code Online (Sandbox Code Playgroud)
......但有缺点:
UIViewAutoresizingFlexibleTopMargin和UIViewAutoresizingFlexibleHeight.[self.view setNeedsLayout]隐藏状态栏后调用.[self.view setNeedsDisplay]隐藏状态栏后调用.wantsFullScreenLayout为YES隐藏状态栏之前和之后.Apple建议UIAlertViews/UIActionSheets在iOS 4中进入后台状态时解除任何一个状态.这是为了避免用户在以后重新启动应用程序时出现任何混淆.我想知道如何能够立刻优雅地解雇所有UIAlertViews,而不是每次我设置它时都不保留对它的引用...
任何的想法 ?
onPostExecute如果AsyncTask取消了会执行吗?
如果它确实执行了,是否可以安全地说我应该isCancelled在开始onPostExecute之前询问任务是否已被取消(),然后再做其他事情?
How do you disable all touch events in an Android WebView (or scrolling in particular)? I would like the activity to handle all touch events.
如果我理解正确的缩放UIView与CGAffineTransform锚改造中心.
特别是:
self.frame = CGRectMake(0,0,100,100);
self.transform = CGAffineTransformMakeScale(2, 2);
NSLog(@"%f;%f;%f;%f", self.frame.origin.x, self.frame.origin.y, self.frame.size.width, self.frame.size.height);
Run Code Online (Sandbox Code Playgroud)
打印:
-50;-50;200;200
Run Code Online (Sandbox Code Playgroud)
如何创建使用特定锚点(例如0; 0)的CGAffineTransform比例?
在Java中创建异步方法的同步版本的最佳方法是什么?
假设你有一个使用这两种方法的类:
asyncDoSomething(); // Starts an asynchronous task
onFinishDoSomething(); // Called when the task is finished
Run Code Online (Sandbox Code Playgroud)
如何doSomething()在任务完成之前实现不返回的同步?
做什么static,extern并且inline(和它们的组合)使用LLVM编译器Objetive-C是什么意思?
另外,我注意到有CG_EXTERN和CG_INLINE宏.我们应该使用那些吗?
(我找不到一个有明确解释的来源,所以我认为在这里创建一个可能有用,或者如果有人知道它可能会指向它)
我想在字符串的所有数字中添加一定数量的前导零(最多3个).例如:
输入: /2009/5/song 01 of 12
输出: /2009/0005/song 0001 of 0012
使用正则表达式执行此操作的最佳方法是什么?
编辑:
我选了第一个正确答案.但是,所有答案都值得一读.
ios ×4
android ×3
iphone ×2
asynchronous ×1
background ×1
bitmap ×1
extern ×1
inline ×1
ios4 ×1
ios6 ×1
java ×1
llvm ×1
objective-c ×1
regex ×1
scaling ×1
static ×1
statusbar ×1
synchronous ×1
touch ×1
uialertview ×1
uistatusbar ×1
webview ×1