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 7751027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T11:26:36+00:00 2026-06-01T11:26:36+00:00

I’m a newbie at iOS development and this is my first question on SO.

  • 0

I’m a newbie at iOS development and this is my first question on SO. My apologies if this is a dumb question.

I’m not using XIBs. My goal is to take a button and to move its position when the device rotates. My problem is that I can not find a way to update / refresh the button’s “frame” on the screen after a rotation takes place.

Here are the 04 files I’m using. I’ve read several other SO questions but I’m unable to fix this issue. Thank you all for any suggestions.

LV_AppDelegate.h

#import <UIKit/UIKit.h>
//
@class LV_ViewController;
//
@interface LV_AppDelegate : UIResponder <UIApplicationDelegate>
//
@property (strong, nonatomic) UIWindow *window;
//
@property (strong, nonatomic) LV_ViewController *viewController;
//
@end

LV_AppDelegate.m

#import "LV_AppDelegate.h"
#import "LV_ViewController.h"
//
@implementation LV_AppDelegate
//
@synthesize window = _window;
@synthesize viewController = _viewController;
//
- (void)dealloc
{
[_window release];
[_viewController release];
[super dealloc];
}
//
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//
NSLog(@"Entering didFinishLaunchingWithOptions");
//
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[LV_ViewController alloc] initWithNibName:@"LV_ViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
//
- (void)applicationWillResignActive:(UIApplication *)application
{
}
//
- (void)applicationDidEnterBackground:(UIApplication *)application
{
}
//
- (void)applicationWillEnterForeground:(UIApplication *)application
{
}
//
- (void)applicationDidBecomeActive:(UIApplication *)application
{
}
//
- (void)applicationWillTerminate:(UIApplication *)application
{
}
//
@end

LV_ViewController.h

#import <UIKit/UIKit.h>
//
@interface LV_ViewController : UIViewController {
    UIButton *button_Narr_Places;
}
//
@property (nonatomic, retain) UIButton *button_Narr_Places;
//
@end

LV_ViewController.m

#import "LV_ViewController.h"
//
//
// - - - - - Open errors: - - - - -
/*
 a.) Local declaration of 'button_Narr_Places' hides instance variable.
 b.) If launched in Landscape, still thinks the device is in Portrait mode, and then 
 rotates to Landscape.
   Launched in Portrait
   Moved to Landscape
 c.) Can not see button once screen is rotated. How to refresh the button's "frame" position after it's updated by "willAnimateRotationToInterfaceOrientation"?
 */
// - - - - - 
@implementation LV_ViewController
//
@synthesize button_Narr_Places;
//
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}
//
- (void)viewDidLoad
{
    [super viewDidLoad];
}
//
- (void)loadView
{
    // - - Create the "view" canvas - -
    UIView *view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
    view.backgroundColor = [UIColor whiteColor];

    //
    // - - - - - Create a button - - - - -
    UIButton *button_Narr_Places    = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    //
    // - - - Adjust position based on INITIAL device orientation - - -
    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
    //
    if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown) {
        NSLog(@"Launched in Portrait");
        button_Narr_Places.frame    = CGRectMake(10, 200, 100,  40);
    }
    else if (orientation == UIDeviceOrientationLandscapeRight || orientation == UIDeviceOrientationLandscapeLeft) {
        NSLog(@"Launched in Landscape");
        button_Narr_Places.frame    = CGRectMake(50, 400, 100,  40);
    }
    // - - - Add button's title, color, selector - - -
    [button_Narr_Places setTitle:@"Places Lived" forState:UIControlStateNormal];
    button_Narr_Places.backgroundColor = [UIColor clearColor];
    button_Narr_Places.tag = 2000;
    [button_Narr_Places addTarget:self action:@selector(method_Narr_Places:) 
                 forControlEvents:UIControlEventTouchUpInside];
    //
    [view addSubview:button_Narr_Places];
    //

    // -- Create a "label" view:
    CGRect frame = CGRectMake(10, 85, 300, 20);
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.textAlignment = UITextAlignmentCenter;
    label.backgroundColor = [UIColor clearColor];
    label.font = [UIFont fontWithName:@"Verdana" size:20];
    label.text = @"Test ViewController.";
    label.tag = 1000;
    //
    [view addSubview:label];
    [label release];
    self.view = view;
}
//
// - - - - - Method called by button above - - - - -
- (IBAction)method_Narr_Places:(id)sender
{
    NSLog(@"Entering method_Narr_Places");
}
//
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration 
{       
    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
    if (orientation == UIDeviceOrientationPortrait) {
        NSLog(@"Moved to Portrait");
        //
        // [button_Narr_Places setFrame:CGRectMake( 10, 778, 100,  40)];
        button_Narr_Places.frame  = CGRectMake( 10, 200, 100,  40);
    }
    else if (orientation == UIDeviceOrientationPortraitUpsideDown) {
        NSLog(@"Moved to Portrait UpsideDown");
    }
    //
    else if (orientation == UIDeviceOrientationLandscapeRight || orientation == UIDeviceOrientationLandscapeLeft) {
        NSLog(@"Moved to Landscape");
        //
        // [button_Narr_Places setFrame:CGRectMake(778, 100, 100,  40)];
        button_Narr_Places.frame  = CGRectMake(50, 400, 100,  40);
    }

}
//
// - - - - - Boilerplate methods below - - - - -
//
- (void)viewDidUnload
{
    [super viewDidUnload];
}
//
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}
//
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}
//
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}
//
- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}
//
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}
//
@end
  • 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-01T11:26:38+00:00Added an answer on June 1, 2026 at 11:26 am

    In your LV_ViewController.m - loadView function, you are declaring the (local) variable for the button like this:

    UIButton *button_Narr_Places    = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    

    This creates a temporary local copy of the button (which “hides” the global property so that you can’t access it in this function) and then throws it away at the end of the function. If you want to be able to reference it later (like in willAnimateRotationToInterfaceOrientation) you need to use the property that you defined in your header file:

    button_Narr_Places    = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    

    or even better:

    self.button_Narr_Places    = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    

    Note that unless you have a reason otherwise, you should be using the self. notation to access the ivar through it’s accessor instead of directly.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.