Why i cannot get the frame of a UIView in order to move it? The view is defined.

Posted by Jann on Stack Overflow See other posts from Stack Overflow or by Jann
Published on 2010-04-12T19:57:29Z Indexed on 2010/04/12 20:43 UTC
Read the original article Hit count: 263

Filed under:
|
|
|
|

I am creating a nav-based app with a view that floats at the bottom of the screen (Alpha .7 most of the time).

I create it like this...

// stuff to create the tabbar/nav bar.
// THIS ALL WORKS...
// then add it to subview.

[window addSubview:tabBarController.view];

// need this last line to display the window (and tab bar controller)
[window makeKeyAndVisible];

// Okay, here is the code i am using to create a grey-ish strip exactly `zlocationAccuracyHeight` pixels high at `zlocationAccuracyVerticalStartPoint` starting point vertically.

CGRect locationManagerAccuracyUIViewFrame = CGRectMake(0,zlocationAccuracyVerticalStartPoint,[[UIScreen mainScreen] bounds].size.width,zlocationAccuracyHeight);
self.locationManagerAccuracyUIView = [[UIView alloc] initWithFrame:locationManagerAccuracyUIViewFrame];
self.locationManagerAccuracyUIView.autoresizingMask = (UIViewAutoresizingFlexibleWidth);
self.locationManagerAccuracyUIView.backgroundColor = [UIColor darkGrayColor];
[self.locationManagerAccuracyUIView setAlpha:0];

CGRect locationManagerAccuracyLabelFrame = CGRectMake(0, 0,[[UIScreen mainScreen] bounds].size.width,zlocationAccuracyHeight);
locationManagerAccuracyLabel = [[UILabel alloc] initWithFrame:locationManagerAccuracyLabelFrame];

if ([myGizmoClass useLocationServices] == 0)
{
 locationManagerAccuracyLabel.text = @"GPS Accuracy: Using Manual Location";
}
else 
{
 locationManagerAccuracyLabel.text = @"GPS Accuracy: One Moment Please...";
}

locationManagerAccuracyLabel.font = [UIFont boldSystemFontOfSize:12];
locationManagerAccuracyLabel.textAlignment = UITextAlignmentCenter;
locationManagerAccuracyLabel.textColor = [UIColor whiteColor];
locationManagerAccuracyLabel.backgroundColor = [UIColor clearColor];
[locationManagerAccuracyLabel setAlpha:0];
[self.locationManagerAccuracyUIView addSubview: locationManagerAccuracyLabel];
[window addSubview: self.locationManagerAccuracyUIView];

this all works (i am not sure about the order i create the uiview in ... meaning i am creating the frame, the view, creating the "accuracy text" and adding that to the view, then adding the uiview as a subview of the window . It works and seems correct in my logic.

So, here is the tough part.

I have a timer that i am testing with. I am trying to float the uiview up by 30 pix.

here is that code:

[UIView beginAnimations:nil context:NULL];  
[UIView setAnimationDuration:0.3];  
CGRect rect = [ self.locationManagerAccuracyUIView frame];
NSLog(@"ORIGIN: %d x %d (%@)\n",rect.origin.x,rect.origin.y,rect);
rect.origin.y -= 30;
[UIView commitAnimations];

The problem? rect is nill, rect.origin.x and rect.origin.y are both zero.

Can anyone tell me why?

Here is how i set up self.locationManagerAccuracyUIView in my files:

Delegate.h

UIView     *locationManagerAccuracyUIView;
UILabel     *locationManagerAccuracyLabel;


...

@property (nonatomic, retain) IBOutlet UIView *locationManagerAccuracyUIView;
@property (nonatomic, retain) IBOutlet UILabel *locationManagerAccuracyLabel;

Delegate.m

...

@synthesize locationManagerAccuracyUIView;
@synthesize locationManagerAccuracyLabel;

...

BTW: Other places in another timer i DO set the alpha to fade in and out and THAT works! So locationManagerAccuracyUIView is valid and defined as a view...

For instance:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[locationManagerAccuracyLabel setAlpha:1];
[UIView commitAnimations];

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[self.locationManagerAccuracyUIView setAlpha:.7];
[UIView commitAnimations];

...and it DOES work. Can anyone help me?

As an aside: I know, when typing this I used self.locationManagerAccuracyUIView and locationManagerAccuracyUIView interchangeably to see if for some reason that was the issue. It is not. :) Thx

© Stack Overflow or respective owner

Related posts about iphone

Related posts about uiview