1

I'm trying to use SwipeView view, i'm making all like in 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;
}

But for some reason i having next issue: 'CALayer position contains NaN: [nan 227]'. On this line of code in SwipeView.m:

view.center = CGPointMake(center.x, _scrollView.frame.size.height/2.0f);

in - (void)setFrameForView:(UIView *)view atIndex:(NSInteger)index; method

After debugging and trying to find reason of this issue i saw that value of property in SwipeView scrollOffset never sets, and it's nil, then i'm setting _scrollOffset in my viewDidLoad method to 1, for example and it's works, but little messes up scrollOffset. In example of SwipeView everything works perfectly without setting this property to any value, any ideas why? Thanks!

PROJECT - github

Similar questions: - CALayer position contains NaN: [nan -0.5] - How to solve CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]?

EDIT:

The problem appears only when i'm pushing view with SwipeView.

Community
  • 1
  • 1
Vlad Z.
  • 3,401
  • 3
  • 32
  • 60

1 Answers1

0

are you adding items to the array for the _swipeView like the example?

- (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)];
    }
}

I have never used SwipeView but It appears the offset is set from the views which are added. Thus this could be your problem.

EDIT: I recreated your problem exactly, you are not connecting your datasource and delegate outlets in your xib or storyboard, control click and drag from your SwipeView to your ViewController and your problem should be fixed!

JAManfredi
  • 777
  • 1
  • 7
  • 19
  • did you connect your delegate and datasource outlets in your xib or storyboard? – JAManfredi Nov 29 '13 at 16:52
  • 2
    Im trying to figure out why this is the case, but it appears if you add `[self.view addSubview:_swipeView]` to your viewDidLoad, it fixes all the problems, I suspect it has to do with the view lifecycle and in which order each frame etc is defined and loaded and thus how its being used in the swipeView. – JAManfredi Nov 29 '13 at 23:56
  • actually this isn't fixing the problem, after i'm trying to add some custom view to this swipeView, and running app, it crashes with error:Assertion failure in -[SwipeView layoutSublayersOfLayer:], Auto Layout still required after executing -layoutSubviews. SwipeView's implementation of -layoutSubviews needs to call super. – Vlad Z. Nov 30 '13 at 11:57
  • after adding [super layoutSubviews]; to end of the layoutSubviews method in swipe view it fixes the problem, i suppose... thanks – Vlad Z. Nov 30 '13 at 11:58