简体   繁体   中英

set the view of iphone view controller

I want to add a UIViewController on my current UIView on a button click event. But I am not able to set the frame. How can I set the y-axis of view. I also checked out iPhone: How to set UIViewController frame? but I can't solve it.

   GalleryViewController *objgallery = [[GalleryViewController 
   alloc]initWithNibName:@"GalleryViewController" bundle:[NSBundle mainBundle]];

    objgallery.view.frame = CGRectMake(0, 88, 320, 372);
    [self presentModalViewController:objgallery animated:YES];

If you are trying to present a modal view that is smaller than the screen, I fear that this is not the way presentModalViewController works. It will always try and enforce its own animation/geometry.

The only way you have to go that I can think of, is creating your own (non-modal) view and then animate it to the position you like. Something along the lines of:

[self.view addSubview: objgallery.view];
[objgallery.view setFrame:CGRectMake(0, 480, 320, 372)];    
[UIView animateWithDuration:0.5 
                 animations:^{
                     [objgallery.view setFrame:CGRectMake(0, 88, 320, 372)];
                 }
                 completion:^(BOOL finished){
                 }];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM