SwipeVIew problem


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
22 views
Trying to understand the SwipeView, the problem occurred when using in your project, use the following code from the example (example 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; }


The app crashes with the error: CALayer position contains NaN: [nan 284] and points to the line
view.center = CGPointMake(center.x, _scrollView.frame.size.height/2.0 f);
.

The entire method:
- (void)setFrameForView:(UIView *)view atIndex:(NSInteger)index { if (self.window) { CGPoint center = view.center; if (_vertical) { center.y = ([self offsetForItemAtIndex:index] + 0.5 f) * _itemSize.height + _scrollView.contentOffset.y; } else { center.x = ([self offsetForItemAtIndex:index] + 0.5 f) * _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.0 f, center.y); } else { view.center = CGPointMake(center.x, _scrollView.frame.size.height/2.0 f); } view.bounds = CGRectMake(0.0 f, 0.0 f, _itemSize.width _itemSize.height); if (disableAnimation && animationEnabled) [UIView setAnimationsEnabled:YES]; } }


When using breakpoints shows that center.x at some point becomes NAN(in comments where indicated). Can't understand what the problem is, like doing everything as in the example. Please help to understand what to do.

EDIT:
Found the cause of the problem: this is due to the fact that there is a Navigation segue from ViewControllera to primary VC c SwipeView.

Github
by | 22 views

1 Answer

0 like 0 dislike
I'm trying to understand why this occurs, but one solution to this problem is to add [self.view addSubview:_swipeView] in your viewDidLoad method. I think the problem with the life cycle and in what order are loaded in the swipeView.
by

Related questions

0 like 0 dislike
3 answers
asked Mar 28, 2019 by nepster
0 like 0 dislike
1 answer
asked Mar 22, 2019 by VasKravchuk
0 like 0 dislike
1 answer
asked Mar 22, 2019 by Project86
0 like 0 dislike
2 answers
110,608 questions
257,187 answers
0 comments
40,252 users