是否可以连续按键?
我正在使用keyCommands:拦截在外部键盘上按下的箭头键,但每次按下我只能拨打1个电话.我希望只要按下按键,每隔X毫秒就可以进行多次调用,或者在按下按键和释放按键时调用.
这是我的代码:
- (NSArray *)keyCommands
{
UIKeyCommand *upArrow = [UIKeyCommand keyCommandWithInput:UIKeyInputUpArrow
modifierFlags:0
action:@selector(upArrow:)];
UIKeyCommand *downArrow = [UIKeyCommand keyCommandWithInput:UIKeyInputDownArrow
modifierFlags:0
action:@selector(downArrow:)];
UIKeyCommand *leftArrow = [UIKeyCommand keyCommandWithInput:UIKeyInputLeftArrow
modifierFlags:0
action:@selector(leftArrow:)];
UIKeyCommand *rightArrow = [UIKeyCommand keyCommandWithInput:UIKeyInputRightArrow
modifierFlags:0
action:@selector(rightArrow:)];
UIKeyCommand *leftArrowCmd = [UIKeyCommand keyCommandWithInput:UIKeyInputLeftArrow
modifierFlags:UIKeyModifierCommand
action:@selector(leftArrowCmd:)];
UIKeyCommand *rightArrowCmd = [UIKeyCommand keyCommandWithInput:UIKeyInputRightArrow
modifierFlags:UIKeyModifierCommand
action:@selector(rightArrowCmd:)];
UIKeyCommand *lCmd = [UIKeyCommand keyCommandWithInput:@"l"
modifierFlags:UIKeyModifierCommand
action:@selector(lCmd:)];
UIKeyCommand *rCmd = [UIKeyCommand keyCommandWithInput:@"r"
modifierFlags:UIKeyModifierCommand
action:@selector(rCmd:)];
UIKeyCommand *mCmd = [UIKeyCommand keyCommandWithInput:@"m"
modifierFlags:UIKeyModifierCommand
action:@selector(mCmd:)];
return @[upArrow, downArrow, leftArrow, rightArrow, leftArrowCmd, rightArrowCmd, lCmd, …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我有一个页面视图控制器,允许用户在应用程序的不同"部分"之间滑动,并在导航栏的顶部我将标题文本更改为用户通过刷过的新部分pageViewController:didFinishAnimating:previousViewControllers:transitionCompleted:.当动画完成时,它当前正在立即更改标题文本.我想通过一些动画改进这一点,一种微妙的淡入淡出效果.
我首先尝试实现[UIView animationWithDuration:...]动画更改标题文本,但它不动画,只是仍然立即更新.
然后我想知道是否有可能更新导航栏标题的alpha,因为用户根据他们滚动的距离水平滚动,当下一部分即将出现在屏幕上时达到0 alpha,然后我可以立即在文本处于0时更改文本,然后快速淡入1 alpha.但是UIPageViewControllerDelegate当滚动位置更新时,我没有看到调用方法.
如果可能的话,我不仅可以淡入淡出,而且可以在导航栏中移动标题文本位置,就像通过滑动手势从推送segue导航回来时发生的默认动画一样.当用户滚动并在另一侧提供下一部分标题时,我会将旧部分标题滑过,这样当转换完成时,前一部分标题不在屏幕上,新的标题完全居中,因此替换完成.但同样需要确切知道用户滚动页面视图控制器的程度.
是否可以实现任何所需的动画?
在我的iOS 7应用程序中,我通过此检入检测到segue是否为popover prepareForSegue:
if ([segue isKindOfClass:[UIStoryboardPopoverSegue class]])
Run Code Online (Sandbox Code Playgroud)
但是现在我正在使用自适应segues,现在作为Popover segue在上面的检查中不再返回true.这是因为segue不再是a UIStoryboardPopoverSegue,而是它UIStoryboardPopoverPresentationSegue.但是,人们不能简单地添加这个Presentation词,因为那里没有定义.
什么是检测segue何时是自适应segue的弹出窗口的适当方法,而不是全屏模式演示?
而且,你如何获得iOS 8的popover参考?以下是我正在为iOS 7做的事情,但同样因为它不会UIStoryboardPopoverSegue导致崩溃.
UIPopoverController *popover = ((UIStoryboardPopoverSegue *)segue).popoverController;
popover.popoverContentSize = CGSizeMake(380, 1000);
Run Code Online (Sandbox Code Playgroud) 我有一个UIPageControl22页,因此22页指示点.在iPhone上的风景中,它们都是可见的,左侧和右侧有足够的空间,但是在纵向中没有足够的水平空间来显示所有的点(至少在iPhone 4和5上),因此两个不可见,外面的两个被切成两半.
我正在寻找一种方法来减少点的大小或减少点之间的填充量,以确保所有点以纵向方式适合屏幕.怎么能实现呢?

我正在编写一个可取消的异步函数,如果任务被取消,它会做很多工作,并散布许多早期返回。当任务成功运行完成或被取消时,我需要执行一些后处理拆卸工作。为了实现这一点,我尝试将此逻辑放入一个defer块中,但这揭示了一个奇怪的错误消息:
\n\n主要参与者隔离属性“isPerformingAsyncWork”无法从主要参与者进行变异
\n
这不是直接矛盾吗,说这个属性只能在主角身上修改,而你不能从主角身上变异它?当任务完成/取消时,您如何解决这个问题或以其他方式执行一些代码?
\n下面是一些示例代码来演示该问题:
\nclass ViewController: UIViewController {\n \n var isPerformingAsyncWork = false\n\n override func viewDidAppear(_ animated: Bool) {\n super.viewDidAppear(animated)\n \n performAsyncWork()\n }\n \n func performAsyncWork() {\n guard !isPerformingAsyncWork else { return }\n \n let alert = UIAlertController(title: "Working on it\xe2\x80\xa6", message: nil, preferredStyle: .alert)\n \n let task = Task {\n defer {\n //called upon task completion or cancelation\n \n //FIXME: Main actor-isolated property 'isPerformingAsyncWork' can not be mutated from the main …Run Code Online (Sandbox Code Playgroud) 我正在制作一个视频应用程序,一个接一个地播放大量视频.视频存储在一个AVPlayerItems 数组中.AVQueuePlayer初始化与那些AVPlayerItems和它自动地从该阵列播放视频.
问题是,当它改变播放下一个视频就被卡住了几分之一秒,或者它从一个到另一个过渡的时间创建了一个混蛋.我想改善与某种动画如淡入这一过渡,而更改视频淡出.
我的代码AVQueuePlayer:
AVQueuePlayer *mediaPlayer = [[AVQueuePlayer alloc] initWithItems:arrPlayerItems];
playerLayer=[AVPlayerLayer playerLayerWithPlayer:mediaPlayer];
playerLayer.frame=self.bounds;
playerLayer.videoGravity = AVLayerVideoGravityResizeAspect;
playerLayer.needsDisplayOnBoundsChange = NO;
[self.layer addSublayer:playerLayer];
self.layer.needsDisplayOnBoundsChange = YES;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(itemPlayEnded:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[mediaPlayer currentItem]];
Run Code Online (Sandbox Code Playgroud)
我试图创建在过渡的时间一个新层,通过降低其不透明度和增加新的图层的不透明度动画旧层(创建淡出效果所需的渐暗),但可根据需要它无法正常工作.
自定义转换的代码:
-(void)TransitionInVideos {
if (roundf(CMTimeGetSeconds(mediaPlayer.currentTime))==roundf(CMTimeGetSeconds(mediaPlayer.currentItem.duration))) {
[self.layer addSublayer:playerLayerTmp];
//Animation for the transition between videos
[self performSelector:@selector(FadeIn) withObject:nil afterDelay:0.3];
[self performSelector:@selector(FadeOut) withObject:nil afterDelay:0.3];
}
}
-(void)FadeIn {
CABasicAnimation* fadeAnim = [CABasicAnimation animationWithKeyPath:@"opacity"];
fadeAnim.fromValue = [NSNumber numberWithFloat:1.0];
fadeAnim.toValue = [NSNumber numberWithFloat:0.0];
fadeAnim.duration …Run Code Online (Sandbox Code Playgroud) 我的应用程序UIVisualEffectView用于模糊背景,就像控制中心一样.但我发现可以运行iOS 8的iPad 2(和Retina iPad)功能不足以显示该效果,因此它恢复为灰色.我希望能够检测到应用程序运行的设备是否足够强大以显示模糊效果,如果不是,我将不会应用它,而是我会将背景颜色更改为看起来比那灰色的颜色.但我不想只是检查设备是iPad 2还是iPad第3代(它是否也会影响第4代?).有没有更好的方法来检测是否UIBlurEffect会出现预期?
我的应用程序允许用户使用Photos框架编辑照片.我看到一些崩溃报告,并且在生成输出图像时出现崩溃,但我不确定问题出在哪里.此崩溃发生在多个硬件设备和多个版本的iOS 9上,包括最新的9.1.我的应用程序最后一次调用是CGImageDestinationFinalize为了创建编辑过的图像NSData.崩溃报告显示在崩溃发生之前,CoreImage空间中的调用继续显示在GLTextureManager中.
这可能是内存不足的问题吗?你看到了这个问题吗?怎么解决这个问题?
从相关的代码PhotoEditor.swift,里面的功能fullImageOutput这与所谓的editSingleAsset它在后台队列运行QOS_CLASS_UTILITY:
let outputPhoto = //the generated CIImage that is the edited photo to be saved to disk
let dataRef = CFDataCreateMutable(nil, 0)
if let destination = CGImageDestinationCreateWithData(dataRef, "public.jpeg", 1, nil) {
struct ContextStruct {
static var ciContext: CIContext? = nil
}
if ContextStruct.ciContext == nil {
let eaglContext = EAGLContext(API: .OpenGLES2)
ContextStruct.ciContext = CIContext(EAGLContext: eaglContext)
}
let cgImage = ContextStruct.ciContext!.createCGImage(outputPhoto, fromRect: outputPhoto.extent)
CGImageDestinationAddImage(destination, cgImage, nil) …Run Code Online (Sandbox Code Playgroud) 在日历中,当您创建新事件时,如果您点击启用了VoiceOver的全天单元格,Siri会说"全天开关按钮打开/关闭,双击以更改设置".实际上,双击将切换开关.此外,不可能只关闭切换开关本身 - 您必须与单元本身交互以切换开关,交换机本身不是可访问的元素.
在我的应用程序中,我使用标签和开关完全相同的设置.但是当我在启用VoiceOver时点击单元格时,它只读取标签,因此盲人用户不知道该单元格中有一个切换开关.如果他们点击开关本身然后他们可以与它交互,所以它与日历应用程序中的设置相反.
如何获得Apple实施的相同行为?我需要一些方法将开关组合到单元格中,以便VoiceOver在突出显示单元格时读取它们,然后当它们双击它时应该切换开关,我不确定如何完成设置.谢谢!
如何UITableView在最顶部插入行而不会导致其余单元格被按下 - 因此滚动位置似乎根本没有变化?
就像Facebook和Twitter在发送新帖子时一样,它们被插入顶部,但滚动位置保持不变.
我的问题类似于这个问题.是什么让我的问题与这个问题的独特之处在于我没有使用具有固定行高的表 - 我正在使用UITableViewAutomaticDimension和一个estimatedRowHeight.因此,建议的答案将无法工作,因为我无法确定行高.
我已经尝试过这个不涉及行高度的解决方案,但contentSize重新加载后仍然不正确,因为该contentOffset集合的相对位置不同 - 单元格仍然被推到插入之前的位置.这是因为单元格尚未在屏幕上呈现,因此iOS无需为它计算适当的高度,直到它即将出现,因此contentSize不准确.
CGSize beforeContentSize = tableView.contentSize;
[tableView reloadData];
CGSize afterContentSize = tableView.contentSize;
CGPoint afterContentOffset = tableView.contentOffset;
tableView.contentOffset = CGPointMake(afterContentOffset.x, afterContentOffset.y + afterContentSize.height - beforeContentSize.height);
Run Code Online (Sandbox Code Playgroud)
阿兰指出rectForCellAtIndexPath哪个力量iOS要计算合适的高度.我现在可以确定插入单元格的正确高度,但是滚动视图contentSize仍然不正确,正如我遍历所有单元格并加起来大于高度的高度所证明的那样contentSize.height.因此,当我contentOffset手动设置时,它不会滚动到正确的位置.
原始代码:
//update data source
[tableView beginUpdates];
[tableView insertRowsAtIndexPaths:newIndexPaths withRowAnimation:UITableViewRowAnimationAutomatic];
[tableView endUpdates];
Run Code Online (Sandbox Code Playgroud)
在这种情况下,可以做些什么来实现所需的行为?
ios ×10
objective-c ×3
uitableview ×2
animation ×1
async-await ×1
avplayer ×1
core-image ×1
crash ×1
ios8 ×1
keyboard ×1
photokit ×1
segue ×1
swift ×1
uiblureffect ×1
uikeycommand ×1
uiresponder ×1
uiscrollview ×1
uiswitch ×1
voiceover ×1