我正在創建一個基於導航的應用程序,其視圖浮動在屏幕的底部(大多數時間爲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