【发布时间】:2013-11-29 13:41:37
【问题描述】:
我正在尝试使用SwipeView 视图,我正在像paging 示例中一样;
- (void)viewDidLoad{
[super viewDidLoad];
_swipeView.pagingEnabled = YES;
}
- (NSInteger)numberOfItemsInSwipeView:(SwipeView *)swipeView{
return [_items count];
}
- (UIView *)swipeView:(SwipeView *)swipeView viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view{
//create new view if no view is available for recycling
if (view == nil)
{
//don't do anything specific to the index within
//this `if (view == nil) {...}` statement because the view will be
//recycled and used with other index values later
view = [[UIView alloc] initWithFrame:self.swipeView.bounds];
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}
//set background color
CGFloat red = arc4random() / (CGFloat)INT_MAX;
CGFloat green = arc4random() / (CGFloat)INT_MAX;
CGFloat blue = arc4random() / (CGFloat)INT_MAX;
view.backgroundColor = [UIColor colorWithRed:red
green:green
blue:blue
alpha:1.0];
return view;
}
- (CGSize)swipeViewItemSize:(SwipeView *)swipeView
{
return self.swipeView.bounds.size;
}
但由于某种原因,我遇到了下一个问题:'CALayer position contains NaN: [nan 227]'。 在 SwipeView.m 中的这行代码:
view.center = CGPointMake(center.x, _scrollView.frame.size.height/2.0f);
在- (void)setFrameForView:(UIView *)view atIndex:(NSInteger)index;方法中
在调试并尝试找到此问题的原因后,我看到 SwipeView scrollOffset 中的属性值从未设置,并且为零,然后我将 viewDidLoad 方法中的 _scrollOffset 设置为 1,例如,它有效,但很少弄乱了滚动偏移。在 SwipeView 的示例中,无需将此属性设置为任何值,一切都可以正常工作,有什么想法吗?谢谢!
项目 - github
类似的问题: - CALayer position contains NaN: [nan -0.5] - How to solve CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]?
编辑:
只有当我使用 SwipeView 推送视图时才会出现问题。
【问题讨论】:
标签: ios objective-c calayer nan