我正在尝试使用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位置包含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,例如它可以工作,但很少弄乱了scrollOffset。在SwipeView的例子中,一切都运行完美,无需将此属性设置为任何值,任何想法为什么?谢谢!
PROJECT - github
类似的问题: - CALayer position contains NaN: [nan -0.5] - How to solve CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]?
编辑:
仅当我使用SwipeView推送视图时才会出现此问题。
答案 0 :(得分:0)
您是否正在为_swipeView的数组添加项目,例如?
- (void)awakeFromNib
{
//set up data
//your swipeView should always be driven by an array of
//data of some kind - don't store data in your item views
//or the recycling mechanism will destroy your data once
//your item views move off-screen
self.items = [NSMutableArray array];
for (int i = 0; i < 100; i++)
{
[_items addObject:@(i)];
}
}
我从未使用过SwipeView但是看起来偏移是根据添加的视图设置的。这可能是你的问题。
修改强>: 我完全重新创建了您的问题,您没有连接数据源并在xib或storyboard中委托出口,控制从SwipeView单击并拖动到ViewController,您的问题应该得到解决!