我试着使用SwipeView视图,我正在制作所有类似于寻呼的例子;
- (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 issue 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的例子中,所有东西都完美地工作,没有将这个属性设置为任何值,有什么想法吗?谢谢!
项目- github
类似的问题:- CALayer职位包含NaN:[nan -0.5] - 如何解决CALayerInvalidGe测‘,原因:'CALayer位置包含NaN:[ nan ]?
编辑:
只有当我使用SwipeView推动视图时,问题才会出现。
发布于 2013-11-29 16:50:02
您是否将项添加到_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或故事板,控制点击和拖动从你的SwipeView到你的ViewController和你的问题应该解决!
https://stackoverflow.com/questions/20287161
复制相似问题