0

Hi I am a beginner in ios and in my ViewController I have loaded Two UIView xib files programmatically they are Test1 and Test2 and I have added one button on this Test1 xib file.

When I click on this button I want to move Test2 xib file using animations.

And for this I have written the code below, but there is no animation happening and Test2 xib file was not added properly(it's added like in the below image) when I tapped on NEXT button.

mycode:-

my MainviwController:-

#import "ViewController.h"

@interface ViewController ()
{
    UIView * MainView;
}

@end

@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    MainView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    MainView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    MainView.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:MainView];

    //Loading xib files inside MainView;

    Test * test1 = [[Test alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    test1.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    [MainView addSubview:test1];

    Test1 * test2 = [[Test1 alloc]initWithFrame:CGRectMake(test1.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height)];
    test2.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
    [MainView addSubview:test2];
}

Test1 xib file class:

#import "Test1.h"

@implementation Test1

-(instancetype)initWithCoder:(NSCoder *)aDecoder{

    if (self = [super initWithCoder:aDecoder]) {

        [self loadingView];
    }
    return self;
}

-(instancetype)initWithFrame:(CGRect)frame{

    if (self = [super initWithFrame:frame]) {

         [self loadingView];
    }
    return self;
}

-(void)loadingView{

    MainView = [[[NSBundle bundleForClass:[self class]]loadNibNamed:@"View1" owner:self
                                                                 options:nil]firstObject];
    [self addSubview:MainView];

    MainView.frame = self.bounds;

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button addTarget:self
               action:@selector(aMethod1:)
     forControlEvents:UIControlEventTouchUpInside];
    [button setTitle:@"NEXT" forState:UIControlStateNormal];
    button.backgroundColor = [UIColor blackColor];
    button.frame = CGRectMake(80.0, 110.0, 100.0, 30.0);
    [MainView addSubview:button];
}

-(void)aMethod1 :(id)sender{

    UIView * view2 = [[[NSBundle bundleForClass:[self class]]loadNibNamed:@"Test2" owner:self
                                                                  options:nil]firstObject];

    [UIView transitionWithView:MainView duration:1
                       options:UIViewAnimationOptionTransitionCurlUp //change animation here
                    animations:^ {
                        [self addSubview:view2];
                    }
                    completion:nil];

}

enter image description here

Elydasian
  • 2,016
  • 5
  • 23
  • 41
Krish
  • 4,166
  • 11
  • 58
  • 110
  • I think this should help http://stackoverflow.com/questions/13885603/problems-with-transitionwithview-and-animatewithduration – Thallius Nov 21 '15 at 07:12
  • no that's not helping to me that's some what diff compare to my question – Krish Nov 21 '15 at 07:24

0 Answers0