Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6079369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:56:19+00:00 2026-05-23T10:56:19+00:00

I want to change my view layout dynamically. how i define in my code?

  • 0

I want to change my view layout dynamically. how i define in my code? In my code i define as

const CGFloat kScrollObjHeight    = 460.0;
const CGFloat kScrollObjWidth    = 320.0;
const NSUInteger kNumImages        = 32;

- (void)layoutScrollImages
{
    UIImageView *view = nil;
    NSArray *subviews = [scrollView1 subviews];

    // reposition all image subviews in a horizontal serial fashion
    CGFloat curXLoc = 0;
    for (view in subviews)
    {
        if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
        {
            CGRect frame = view.frame;
            frame.origin = CGPointMake(curXLoc, 0);
            view.frame = frame;

            curXLoc += (kScrollObjWidth);
        }
    }

    // set the content size so it can be scrollable
    [scrollView1 setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), [scrollView1 bounds].size.height)];
}

- (void)viewDidLoad
{
    self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];

    // 1. setup the scrollview for multiple images and add it to the view controller
    //
    // note: the following can be done in Interface Builder, but we show this in code for clarity
    [scrollView1 setBackgroundColor:[UIColor blackColor]];
    [scrollView1 setCanCancelContentTouches:NO];
    scrollView1.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    scrollView1.clipsToBounds = YES;        // default is NO, we want to restrict drawing within our scrollview
    scrollView1.scrollEnabled = YES;

    //imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image0.jpg"]];
    [scrollView1 addSubview:imageView];
    [scrollView1 setContentSize:CGSizeMake(imageView.frame.size.width, imageView.frame.size.height)];
    scrollView1.minimumZoomScale = 1;
    scrollView1.maximumZoomScale = 3;
    scrollView1.delegate = self;
    [scrollView1 setScrollEnabled:YES];

    // pagingEnabled property default is NO, if set the scroller will stop or snap at each photo
    // if you want free-flowing scroll, don't set this property.
    scrollView1.pagingEnabled = YES;

    // load all the images from our bundle and add them to the scroll view
    NSUInteger i;
    for (i = 1; i <= kNumImages; i++)
    {
        NSString *imageName = [NSString stringWithFormat:@"page-%d.jpg", i];
        UIImage *image = [UIImage imageNamed:imageName];
        UIImageView *ImageView = [[UIImageView alloc] initWithImage:image];

        // setup each frame to a default height and width, it will be properly placed when we call "updateScrollList" 
        CGRect rect = ImageView.frame;
        rect.size.height = kScrollObjHeight;
        rect.size.width = kScrollObjWidth;
        ImageView.frame = rect;
        ImageView.tag = i;    // tag our images for later use when we place them in serial fashion
        [scrollView1 addSubview:ImageView];
        [ImageView release];
    }

    [self layoutScrollImages];    // now place the photos in serial layout within the scrollview


}

-(UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return imageView;
}


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    return YES;
}


- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];


    switch(toInterfaceOrientation){
        case (UIInterfaceOrientationLandscapeLeft):
        {
            landscapeModeViewController=[[LandscapeModeViewController alloc] initWithNibName:@"LandscapeModeViewController" bundle:nil];
            [self.view addSubview:landscapeModeViewController.view];
            /*UIAlertView *info = [[UIAlertView alloc] initWithTitle:@"Info" message:@"change Mode" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [info show];
            [info release];*/
        }
            break;
        case(UIInterfaceOrientationLandscapeRight):
        {
            //landscapeModeViewController=[[LandscapeModeViewController alloc] initWithNibName:@"LandscapeModeViewController" bundle:nil];
            //[self.view addSubview:landscapeModeViewController.view];
            UIAlertView *info = [[UIAlertView alloc] initWithTitle:@"Info" message:@"change Mode" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [info show];
            [info release];
        }
            break;
        case(UIInterfaceOrientationPortrait):
        {
            //portraitMode=[[PortraitMode alloc] initWithNibName:@"PortraitMode" bundle:nil];
            //[self.view addSubview:portraitMode.view];
            UIAlertView *info = [[UIAlertView alloc] initWithTitle:@"Info" message:@"change Mode" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [info show];
            [info release];

        }
            break;

            /*if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
             UIAlertView *info = [[UIAlertView alloc] initWithTitle:@"Info" message:@"Select Landscape mode." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
             [info show];
             [info release];
             [scrollView1 release];
             landscapeModeViewController=[[LandscapeModeViewController alloc] initWithNibName:@"LandscapeModeViewController" bundle:nil];
             [self.view addSubview:landscapeModeViewController.view];


             }


             else{
             UIAlertView *info = [[UIAlertView alloc] initWithTitle:@"Info" message:@"Select Portrait Mode" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
             [info show];
             [info release];

             portraitMode=[[PortraitMode alloc] initWithNibName:@"PortraitMode" bundle:nil];
             [self.scrollView1 addSubview:portraitMode.view];
             }  */  


    }
}
- (void)dealloc
{    
    [scrollView1 release];
    [imageView release];

    [super dealloc];
}

- (void)didReceiveMemoryWarning
{

    [super didReceiveMemoryWarning];
}

@end

in above code when rotate device then uialerview execute but previous view not release and landsacpe mode shown behind him. so what i will do for that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:56:20+00:00Added an answer on May 23, 2026 at 10:56 am

    You can set autoresize mask to each view in your layout in whatever manner you want.

    For example, if you want button to show always on top left corner, you can set auto resize mask to flexible top and left..

    If your layout is totally different in portrait and landscape, then you need to set frames in willRotateToInterfaceOrientation.

    For example if you want your button on top left in portrait and in center in landscape, than you need to set frame in the above delegate method.

    Edit Answer:

     if(UIInterfaceOrientationIsLandscape(toInterfaceOrientation)){
        if(!landscapeModeViewController){
             landscapeModeViewController=[[LandscapeModeViewController alloc] initWithNibName:@"LandscapeModeViewController" bundle:nil];
        }
        [self.view addSubview:landscapeModeViewController.view];
        [self.view bringSubviewToFront:landscapeModeViewController.view];
     }
     else if(UIInterfaceOrientationIsPortrait(toInterfaceOrientation)){
         if(!portraitMode){
             portraitMode=[[PortraitMode alloc] initWithNibName:@"PortraitMode" bundle:nil];
         }
         [self.view addSubview:portraitMode.view];
         [self.view bringSubviewToFront:portraitMode.view];
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to change the view size for iPhone 3.0, but I find that
i'm programming with opengl and i want to change the camera view: ... void
I want to change an image on a view, from a popup dialog of
I'm using AvalonDock to layout my application. I want to create a View MenuItem
I have two button and want to change layout content on click button on
I want to change layout background dynimically. Here is the log from the LogCat:
I'd like my VIEW layout to be adjusted on orientation change. My Manifest is
I've created a gallery, and now I want to change it in the code.
I have a View (called MyView) in my Layout file. I want to content
I want to change the Text of the browse button in the FileUpload Control

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.