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

  • SEARCH
  • Home
  • 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 8190277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:34:08+00:00 2026-06-07T03:34:08+00:00

I am using UIView subclass to add my detail view in my UIViewController .

  • 0

I am using UIView subclass to add my detail view in my UIViewController. My UIViewController has on UIView and adding Detail subview to it.

here is my code.

#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import "DetailView.h"

@interface ViewController : UIViewController{
    AppDelegate *appDelegate;

    IBOutlet UILabel *lblAdd;

    IBOutlet UIView *viewDetail;

    DetailView *viewDetailfinal;
}
@property (nonatomic, retain) DetailView *viewDetailfinal;

-(IBAction) show;
-(IBAction) viewDetailHide;

@end

#import "ViewController.h"
#define detailPortraitWidth 478
#define detailPortraitHeight 899
#define detailLandscapeWidth 733
#define detailLandscapeHeight 642

#define viewDetailHeaderHeight 150

@implementation ViewController
@synthesize viewDetailfinal;


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    viewDetailfinal.curOrientation = [UIDevice currentDevice].orientation;
    return YES;
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
    BOOL isPortrait = UIDeviceOrientationIsPortrait(self.interfaceOrientation);
    if (isPortrait) {
        if (!viewDetail.isHidden) {

            [viewDetailfinal selfSetFrame:CGRectMake(0, viewDetailHeaderHeight, detailPortraitWidth , detailPortraitHeight-viewDetailHeaderHeight)];
            [viewDetailfinal loadCommonView];
        }
    }
    else{
        if (!viewDetail.isHidden) {
            [viewDetailfinal selfSetFrame:CGRectMake(0, viewDetailHeaderHeight, detailLandscapeWidth , detailLandscapeHeight-viewDetailHeaderHeight)];
            [viewDetailfinal loadCommonView];
        }
    }

}
-(IBAction) show{
    BOOL isPortrait = UIDeviceOrientationIsPortrait(self.interfaceOrientation);
    if (isPortrait) {
        if (viewDetail.isHidden) {
            viewDetail.hidden=NO;            
            [self.view addSubview:viewDetail];

            viewDetailfinal = [[DetailView alloc] initWithFrame:CGRectMake(0, viewDetailHeaderHeight, detailPortraitWidth, detailPortraitHeight-viewDetailHeaderHeight)];

            viewDetailfinal.curOrientation = UIDeviceOrientationPortrait;

            [viewDetail addSubview:viewDetailfinal];
            [viewDetailfinal loadCommonView];
        }
        else{
            viewDetailfinal.curOrientation = UIDeviceOrientationPortrait;
            [viewDetailfinal selfSetFrame:CGRectMake(0, viewDetailHeaderHeight, detailPortraitWidth, detailPortraitHeight-viewDetailHeaderHeight)];
        }
    }
    else{
        if (viewDetail.isHidden) {
            viewDetail.hidden=NO;

            [self.view addSubview:viewDetail];

            viewDetailfinal = [[DetailView alloc] initWithFrame:CGRectMake(0, viewDetailHeaderHeight, detailLandscapeWidth , detailLandscapeHeight-viewDetailHeaderHeight)];

            viewDetailfinal.curOrientation = UIDeviceOrientationLandscapeLeft;

            [viewDetail addSubview:viewDetailfinal];
            [viewDetailfinal loadCommonView];
        }
        else{
            viewDetailfinal.curOrientation = UIDeviceOrientationLandscapeLeft;
            [viewDetailfinal selfSetFrame:CGRectMake(0, viewDetailHeaderHeight, detailLandscapeWidth, detailLandscapeHeight-viewDetailHeaderHeight)];

        } 
    } 
}

-(IBAction) viewDetailHide{
    [viewDetailfinal releaseMemory];

    viewDetail.hidden=YES;
}

// My Detail View

#import <UIKit/UIKit.h>

@interface DetailView : UIView{
    UIScrollView *scrlViewMain;
    UIDeviceOrientation curOrientation;
}
@property UIDeviceOrientation curOrientation;
@property (nonatomic, retain) UIScrollView *scrlViewMain;

-(void) selfSetFrame:(CGRect)frame;
-(void) releaseMemory;
-(void) loadCommonView;
@end



#define scrlViewMainX 0
#define scrlViewMainY 0
#define scrlViewMainWidth 468
#define scrlViewMainPortHeight 749
#define scrlViewMainLandHeight 492

@implementation DetailView
@synthesize scrlViewMain;
@synthesize curOrientation;
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self setFrame:frame];
        scrlViewMain = [[UIScrollView alloc] init];
    }
    return self;
}
-(void) selfSetFrame:(CGRect)frame{
    [self setFrame:frame];
    if (curOrientation == UIDeviceOrientationPortrait || curOrientation == UIDeviceOrientationPortraitUpsideDown) {
        [self.scrlViewMain setFrame:CGRectMake(scrlViewMainX, scrlViewMainY, scrlViewMainWidth, scrlViewMainPortHeight)];
}
    else{
        [self.scrlViewMain setFrame:CGRectMake(scrlViewMainX, scrlViewMainY, scrlViewMainWidth, scrlViewMainLandHeight)];
}
    [self.scrlViewMain setContentSize:CGSizeMake(scrlViewMainWidth, 1500)];
}
-(void) loadCommonView {
    if (curOrientation == UIDeviceOrientationPortrait || curOrientation == UIDeviceOrientationPortraitUpsideDown) {
        [self.scrlViewMain setFrame:CGRectMake(scrlViewMainX, scrlViewMainY, scrlViewMainWidth, scrlViewMainPortHeight)];
    }
    else{
        [self.scrlViewMain setFrame:CGRectMake(scrlViewMainX, scrlViewMainY, scrlViewMainWidth, scrlViewMainLandHeight)];
}
    [self.scrlViewMain setBackgroundColor:[UIColor redColor]];
    [self addSubview:scrlViewMain];
}
-(void) releaseMemory{
    [scrlViewMain release];
    [self release];
}
@end

my problem is that when i am hiding the detail view and open detail view in different orientation my view become like this.

enter image description here

the red color is of scrollview. can anyone check this code and let me know what is the problem. Any help will be appreciated.

  • 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-06-07T03:34:10+00:00Added an answer on June 7, 2026 at 3:34 am

    You need to add the autoResizing flags and mask. Try this:

    scrlViewMain = [[UIScrollView alloc] init];
    scrlViewMain.autoresizesSubviews = YES:
    scrlViewMain.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    

    I suggest you also look at the docs for these properties on UIView and their subclasses. The masks can be used to cause your view to remain in the same relative position to the top or bottom, or not depending on how you use them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In an iPad app, I'm using a custom subclass of UIView with UIViewController. Here's
I'm using the following code to load a xib in my UIView subclass named
I'm using this code in my UIView subclass to draw a circle with a
I am using following code to color image on touch event.I have subclass uiview
In my HypnosisViewController.m I have this code for adding a UIView subclass, HypnosisView to
I have a UIView on top of another view that's using a UITouchGesture. The
I have a view with a custom slider. We are using a subclass of
I perform custom drawing in my UIView subclass using: - (void)drawRect:(CGRect)rect; How can I
I have a UIView subclass. This subclass has multiple subviews. Is it possible to
I have a a singleton class here is the code #import <Foundation/Foundation.h> #import CustomColor.h

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.