Jean
Jean

Reputation: 2625

Why doesn't the UIView frame not set?

Am trying something so trivial! Can't believe it's not working! Maybe am overlooking something! Am having a home page in my iPhone app. I want to now add a subview which will be initially out of the screen (i.e. hidden to the right i.e. its frame.origin.x will be the screen width), and then I want to animate its entry into the page with a flip-horizontal and show the subview partially (only half-screen approximately).

[self.mySubview.view setFrame:CGRectMake([[UIScreen mainScreen] bounds].size.width, 0.0,
                                                 [[UIScreen mainScreen] bounds].size.width,
                                                 [[UIScreen mainScreen] bounds].size.height)];
[self.view addSubview:self.mySubview.view];
NSLog(@"frame before x %f", self.mySubview.view.frame.origin.x);

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
      [self.mySubview.view setFrame:CGRectMake([[UIScreen mainScreen] bounds].size.width*(2/5), 0.0,
                                                       [[UIScreen mainScreen] bounds].size.width,
                                                       [[UIScreen mainScreen] bounds].size.height)];
[UIView commitAnimations];
NSLog(@"frame x %f", self.mySubview.view.frame.origin.x);

Am trying to run this on an iPad. But the subview's frame is not getting set to 768.0 initially. Also, the animation is not happening. Before and after the animation, the subview's frame.origin.x is only 0.0. Where could I have gone wrong? Please help. I tried varying the autosizing arrows in the storyboard (removing them, adding them) ... nothing seems to work!

Upvotes: 1

Views: 579

Answers (2)

nivrit gupta iphone
nivrit gupta iphone

Reputation: 121

Try This

   Someviewcontroller *c = initWithNibName
     c.view.frame = CGRectMake(0, 0, 200, 200);
     [self addSubView:c];

Upvotes: 1

SAMIR RATHOD
SAMIR RATHOD

Reputation: 3506

Try this:

    self.mySubview

instend of

    self.mySubview.view

Upvotes: 0

Related Questions