我正在创建一个基于导航的应用程序,其视图浮动在屏幕的底部(大多数时间为Alpha .7)。为什么我无法获得UIView的框架来移动它?
我创建它像这样...
// 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];
这一切工作(我不知道我在...这意味着我创建的框架,在视图中创建了UIView的顺序,创建“准确的文本”,并补充说,到视图,然后添加的UIView作为窗口的子视图,它的工作原理,并在我的逻辑似乎是正确的。
所以,这里是最困难的部分。
我有一个定时器,我正在测试。我想浮动uiview由30像素。
这里是代码:
[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];
的问题? rect is nill,rect.origin.x和rect.origin.y都是零。
有谁能告诉我为什么?
这是我如何设置在我的文件self.locationManagerAccuracyUIView:
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:其他地方另一个定时器,我设置alpha淡入和淡出效果!所以locationManagerAccuracyUIView是有效的,定义为一个视图...
例如:
[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];
...和它的工作。谁能帮我?另外:我知道,在输入这个字符时,我互换地使用了self.locationManagerAccuracyUIView
和locationManagerAccuracyUIView
以查看是否由于某种原因导致问题出现。不是这样。 :) Thx
这工作 - 太棒了!我不知道为什么我没有把修剪矩形放回到UIView对象中。感谢您思考并详细解释 - 当我没有想到的时候。已投票接受答案! – Jann 2010-04-12 22:16:31