- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
当我在 iPad 上运行时,我的应用程序出现此错误:
Uncaught exception: CALayer position contains NaN
相同的代码在 iPhone 上运行良好。
- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
AnnotationView *aV;
for (aV in views) {
// Don't pin drop if annotation is user location
if ([aV.annotation isKindOfClass:[MKUserLocation class]]) {
continue;
}
// Check if current annotation is inside visible map rect, else go to next one
MKMapPoint point = MKMapPointForCoordinate(aV.annotation.coordinate);
if (!MKMapRectContainsPoint(mapViewResult.visibleMapRect, point)) {
continue;
}
CGRect endFrame = aV.frame;
// Move annotation out of view
// I checked here, CGRectEmpty returns true here
aV.frame = CGRectMake(aV.frame.origin.x, aV.frame.origin.y - self.view.frame.size.height, aV.frame.size.width, aV.frame.size.height);
// Animate drop
[UIView animateWithDuration:0.5 delay:0.04*[views indexOfObject:aV] options: UIViewAnimationOptionCurveLinear animations:^{
aV.frame = endFrame;
// Animate squash
}completion:^(BOOL finished){
if (finished) {
[UIView animateWithDuration:0.05 animations:^{
aV.transform = CGAffineTransformMakeScale(1.0, 0.8);
}completion:^(BOOL finished){
if (finished) {
[UIView animateWithDuration:0.1 animations:^{
aV.transform = CGAffineTransformIdentity;
}];
}
}];
}
}];
}
}
我了解到,分配的帧包含 NaN
值,我使用 CGRectEmpty
函数检查了这一点并将该帧设置为 CGRectZero
但它不会工作。
我从这里得到了这个工作代码,https://stackoverflow.com/a/7045916/1603234
回溯/调试日志
*** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [594.947 nan]'
*** First throw call stack:
(
0 CoreFoundation 0x048551e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x034ad8e5 objc_exception_throw + 44
2 CoreFoundation 0x04854fbb +[NSException raise:format:] + 139
3 QuartzCore 0x01a1be1a _ZN2CA5Layer12set_positionERKNS_4Vec2IdEEb + 190
4 QuartzCore 0x01a1bfd9 -[CALayer setPosition:] + 68
5 QuartzCore 0x01a1c6df -[CALayer setFrame:] + 799
6 UIKit 0x01fbbb4d -[UIView(Geometry) setFrame:] + 302
7 MyAppName 0x0026b025 -[ResultMapViewController mapView:didAddAnnotationViews:] + 2133
8 MapKit 0x01e0449b -[MKMapView annotationManager:didAddAnnotationRepresentations:] + 272
9 MapKit 0x01e3b53c -[MKAnnotationManager updateVisibleAnnotations] + 2052
10 Foundation 0x02ed6de7 __NSFireTimer + 97
11 CoreFoundation 0x04813ac6 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22
12 CoreFoundation 0x048134ad __CFRunLoopDoTimer + 1181
13 CoreFoundation 0x047fb538 __CFRunLoopRun + 1816
14 CoreFoundation 0x047fa9d3 CFRunLoopRunSpecific + 467
15 CoreFoundation 0x047fa7eb CFRunLoopRunInMode + 123
16 GraphicsServices 0x03ccd5ee GSEventRunModal + 192
17 GraphicsServices 0x03ccd42b GSEventRun + 104
18 UIKit 0x01f60f9b UIApplicationMain + 1225
19 MyAppName 0x0001ba3d main + 141
20 MyAppName 0x000027e5 start + 53
)
libc++abi.dylib: terminating with uncaught exception of type NSException
最佳答案
我的天哪!我不知道我会犯这种“愚蠢”的错误。
是的,有问题的句子 相同的代码在 iPhone 上运行良好。 我收到错误 CALayer position contains NaN
因为在我的自定义 - (AnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id ) annotation
方法,我在这里计算
annotationView.layer.anchorPoint = CGPointMake(0.5, 1.0 - (diffFromBottom * 1.0)/annotationView.image.size.height);
annotationView.image 是空白的,因为我忘记在 iPad 项目中添加图钉图像。它存在于 iPhone 代码中。因此它被零 (0) 除并导致错误。
我放了断点,然后用 NSLog
打印就知道了,
1.0 - (diffFromBottom * 1.0)/annotationView.image.size.height
打印了这个值,-inf
。这导致了应用程序崩溃。
基本上,如果您执行除以无穷大或零时会发生此错误,因此每当您遇到此类错误时,首先查看执行除法运算的代码。
关于ios - 未捕获的异常 : CALayer position contains NaN when doing animation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22935599/
我想使用 linux 终端在 .txt 文档中找到字符串 animal-0**。 ** 是从 60 到 69 的数字。我想我必须在命令中使用 grep 和正则表达式:grep -E 'animal-0
在他的C# 深入一书中,Jon Skeet 试图回答以下问题: Why can't I convert List to List? 为了解释它,他从一个代码片段开始,其中包括以下两行: Animal[
我对此有点困惑,所以希望能提供一些说明。 public void addAll(List animals) 对比 public void addAll(List animals) 最佳答案 区别在于
我遇到的情况是,我有许多CALayer以“基于回合”的方式进行动画处理。我为每个CALayer上的位置设置了动画,但是它们具有完全相同的持续时间。一旦所有这些CALayer动画完成,就会启动一个新的“
我为正在拔出的刀和空闲状态设置了动画,但是无论我做什么,它们都不会在游戏中设置动画。相反,它卡住在第一帧上。这是动画窗口运行时的样子: 动画: 在检查器中: 最佳答案 我遇到了类似的问题,它归结于动画
我的单个 HTML 文件中嵌入了 2 个页面。所以它所做的是最初它显示 PAGE1,然后如果我从右向左或从左向右滑动 PAGE2 应该显示。我的问题是如何根据我的滑动更改页面动画?比如当我从右向左滑动
我想做一个动画标题。 我创建了一个 FlatList 的动画组件, 用过 onScroll函数来更新动画值。 使用绝对位置放置一个 View (Animated.View) 作为动画 FlatList
我想制作一个打开的窗帘的动画。我有两张图像:一张用于窗帘的左侧,一张用于窗帘的右侧(以红色表示)。我想用核心动画顺利地将它们滑走。我应该寻找什么类型的动画?如何实现逼真的滑动风格? 问候, 斯特凡 a
我有一个简单的旋转动画,可以让一个对象绕其轴旋转。目前它旋转得太快了,我想减慢速度,我试过增加样本??但我对动画了解不多,所以我可能过得很好。如何放慢动画速度?它只有两个键。 最佳答案 首先,通过双击
我似乎无法在上类时获得 angularjs ng-animate,而且在野外似乎也没有任何示例。以演示 fiddle 为例: http://jsfiddle.net/yfajy/ 向 CSS 添加如下
使用以下代码段:http://jsfiddle.net/sylouuu/V7a3Y/2/ 我想在动画的#log 中显示从 0% 到 100% 的进度百分比,100% 很容易通过回调... 有可能这样做
我正在 HTML 中使用 SVG 来使用折线工具定义特定的形状。我希望通过按一下按钮并在几秒钟内将特定形状的外观动画化为不同的形状。 我一直在考虑使用动画工具来更改折线点属性,但到目前为止一直无法找到
您好,在 Firefox(相当糟糕)和 Chrome 之间获得可变性能和效果(还可以)有时这不会执行第一个动画,有时会卡住。 我的结构正确吗? $notification.animate({
我在 iOS 编程时遇到了一个问题:当我尝试为我的 tableView 制作自定义编辑按钮时,我无法将其设置为动画。下面是我如何初始化 tableview: - (void)viewWillAppea
自 beta 5 以来,我注意到在 OS X 10.10 下隐式动画有一些奇怪的行为。调用动画代理有时会导致应用程序崩溃。我设置了一个非常简单的自定义 View 。这是完整的代码: import Co
我正在开发一个可折叠组件,您可以单击它来向上/向下滚动以显示/隐藏详细信息。组件如下: // component.ts import {Component, Directive, Input} fro
我正在努力了解 web animations standard和他们的 polyfill ,正如我所见,它在 Angular 动画库中运行良好(您将动画结束值设置为“*”,这将变为 div 大小的 1
我想创建一个动画闪屏,但出现此错误: Android.Content.Res.Resources+NotFoundException: File res/drawable/splash_screen.
我正在尝试对我的应用程序应用慢动作效果,就像按 Shift 时如何减慢 Mac OS 的大多数图形效果一样。 我的应用程序使用 CoreAnimation,所以我认为它应该没什么大不了的:set sp
我想以编程方式同时不在XML文件中显示两个动画,它应该 ROTATE和TRANSLATE 我怎样才能做到这一点? 请以某种方式建议我?????? 这是ma代码:> ImageView snowImg1
我是一名优秀的程序员,十分优秀!