ealeksandrov / EAIntroView

Highly customizable drop-in solution for introduction views.
MIT License
3.76k stars 501 forks source link

IntroView as an IBOUTLET #2

Closed elpuerco63 closed 10 years ago

elpuerco63 commented 10 years ago

Is it possible to have an init from Storyboard? So you could place the introView in the storybard and then in the viewcontroller's viewdidload make a call to set the pages?

I guess this falls into the reload pages bit? I'm finding that by adding the introview in code it does not follow the autolayout setup in the storyboard?

so for example if starting in landscape the images appear ok but when rotating to portrait the introview remains in portrait...

ealeksandrov commented 10 years ago

In #3 I suggested pages reloading using custom property setter approach. This way we can do view init via storyboard or xib.

ealeksandrov commented 10 years ago

You can test new pages setter now. Please review your issue. Maybe we will need some more tweaks, so pages will conform to autolayout.

elpuerco63 commented 10 years ago

This is brilliant! Thanks, the pages update upon rotation as required...perfect ;-)

I'm trying to see now what happens if I plug a EAIntroView in the XIB and add autolayout...

elpuerco63 commented 10 years ago

Hi, have added a view to xib and IBOUTLET to viewcontroller but cannot get pages to set using setPages? I not that from the xib initWithCoder is called and have tried this:

-(id)initWithCoder:(NSCoder *)aDecoder {
    NSLog(@"coder");
    if (self = [super initWithCoder:aDecoder]) {
        pageViews = [[NSMutableArray alloc] init];
        self.swipeToExit = YES;
        self.hideOffscreenPages = YES;
        self.titleViewY = 20.0f;
        self.pageControlY = 60.0f;
        [self setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
    }

    return self;
}

but I still get blank view...obviously missing something simple here?

elpuerco63 commented 10 years ago

this probably was the way I should have been doing it, but even with AutoLayout set in VC still goes odd...

-(id)awakeAfterUsingCoder:(NSCoder *)aDecoder {

    self = [super awakeAfterUsingCoder:aDecoder];

    if (self = [super initWithCoder:aDecoder]) {
        pageViews = [[NSMutableArray alloc] init];
        self.swipeToExit = YES;
        self.hideOffscreenPages = YES;
        self.titleViewY = 20.0f;
        self.pageControlY = 60.0f;
        [self buildUIWithFrame:self.frame];
        [self setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight];
    }

    return self;
}
ealeksandrov commented 10 years ago

You forgot [self buildUIWithFrame:self.frame]; in your first answer. With it initWithCoder is working well for me (setting pages for EAIntroView from storyboard).

But I didn't test AutoLayout. What is odd with it?

elpuerco63 commented 10 years ago

Hi, see my later post re using awakeAfterUsingCoder that includes the call to buildframe ;-)

I have introview in my xib connected to an iboutlet and the viewcontroller has in the xib use autolayout turned on.

Then when the device rotate in response to a notification this code gets called:

-(void)didRotate:(NSNotification *)notification {

    EAIntroPage *page1 = [EAIntroPage page];
    EAIntroPage *page2 = [EAIntroPage page];

    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;

    if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) { // home button to left

        page1.bgImage = [UIImage imageNamed:@"Page1-Landscape.png"];
        page2.bgImage = [UIImage imageNamed:@"Page2-Landscape.png"];

    }
    else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) { // home button to bottom

        if ([UIScreen mainScreen ].bounds .size.height == 568) {

            page1.bgImage = [UIImage imageNamed:@"Page1-568h@2x.png"];
            page2.bgImage = [UIImage imageNamed:@"Page2-568h@2x.png"];
        }
        else {

            page1.bgImage = [UIImage imageNamed:@"Page1.png"];
            page2.bgImage = [UIImage imageNamed:@"Page2.png"];
        }
    }

    [self.intro setPages:@[page1, page2]];

    self.intro.pageControl.pageIndicatorTintColor = kAppColour;

    self.intro.pageControl.currentPageIndicatorTintColor = kCurrentPageDotColour;

}

and this works in that when rotating the images are updated but when in landscape the intro view appears to be still in portrait taking up just over half the left of the screen with the landscape image squashed in it...

ealeksandrov commented 10 years ago

In 8af17c475ea25916f185a7dd6b5c770869e6a597 I've added autoresizing for backgrounds and scrollView positioning at IntroView's center (it was in corner all previous time). It adds some autorotation and autoresize support, whilst to successfully resize all pages we have to rebuilt their views inside scrollView on rotation. This will add unnecessary complexity, so right now I prefer to avoid it.