Answer the question
In order to leave comments, you need to log in
SwipeView problem
I'm trying to understand SwipeView , there was a problem when using it in my project, I use the following code from the example (Paging example) :
-(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 284]
and points to a line withview.center = CGPointMake(center.x, _scrollView.frame.size.height/2.0f);
. - (void)setFrameForView:(UIView *)view atIndex:(NSInteger)index
{
if (self.window)
{
CGPoint center = view.center;
if (_vertical)
{
center.y = ([self offsetForItemAtIndex:index] + 0.5f) * _itemSize.height + _scrollView.contentOffset.y;
}
else
{
center.x = ([self offsetForItemAtIndex:index] + 0.5f) * _itemSize.width + _scrollView.contentOffset.x;// center.x NAN
}
BOOL disableAnimation = !CGPointEqualToPoint(center, view.center);
BOOL animationEnabled = [UIView areAnimationsEnabled];
if (disableAnimation && animationEnabled) [UIView setAnimationsEnabled:NO];
if (_vertical)
{
view.center = CGPointMake(_scrollView.frame.size.width/2.0f, center.y);
}
else
{
view.center = CGPointMake(center.x, _scrollView.frame.size.height/2.0f);
}
view.bounds = CGRectMake(0.0f, 0.0f, _itemSize.width, _itemSize.height);
if (disableAnimation && animationEnabled) [UIView setAnimationsEnabled:YES];
}
}
Answer the question
In order to leave comments, you need to log in
I'm trying to figure out why this is happening, but one solution to this problem is to add [self.view addSubview:_swipeView] to your viewDidLoad method. I think that the problem is with the life cycle and in what sequence the loading occurs in the swipeView itself.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question