Objective c UIView“;";在UITabBarController视图左上角

Objective c UIView“;";在UITabBarController视图左上角,objective-c,cocoa-touch,uiview,positioning,Objective C,Cocoa Touch,Uiview,Positioning,我正在初始化加载程序子视图,以匹配用于包装我的应用程序的UITabBar的高度、宽度和位置: // In UITabBarController implementation LoaderView *loaderView = [[LoaderView alloc] initWithFrame:[self tabBar].viewForBaselineLayout.frame]; [[self view] addSubview:loaderView]; // // LoaderView.h

我正在初始化加载程序子视图,以匹配用于包装我的应用程序的UITabBar的高度、宽度和位置:

// In UITabBarController implementation

LoaderView *loaderView = [[LoaderView alloc] initWithFrame:[self tabBar].viewForBaselineLayout.frame];
[[self view] addSubview:loaderView];

//
//  LoaderView.h

#import <UIKit/UIKit.h>

@interface LoaderView : UIView

@property (nonatomic, strong) UILabel *messageLabel;
@property (nonatomic, strong) NSString *message;
@property (nonatomic) CGRect frame;

- (void)createLabel;
- (void)drawLoader;
- (void)setText:(NSString *)newMessage;
- (void)show:(NSNotification *)notification;

@end

//
//  LoaderView.m

#import "LoaderView.h"

@implementation LoaderView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self drawLoader];
    }
    return self;
}

- (void)drawLoader
{
    UIColor *semiOpaqueGray = [[UIColor alloc] initWithRed:0.0f green:0.0f blue:0.0f alpha:0.8f];
    [self setBackgroundColor:semiOpaqueGray];

    [self createLabel];
}

- (void)createLabel
{
    _messageLabel = [[UILabel alloc] initWithFrame: CGRectMake(15,9,([self frame].size.width - 10), 30)];
    _messageLabel.textColor = [[UIColor alloc] initWithWhite:1.0 alpha:1];
    _messageLabel.backgroundColor = [[UIColor alloc] initWithWhite:1.0 alpha:0.0];

    [self addSubview:_messageLabel];
}

@end
结果就是这样。在左上角可以看到不透明的黑框。它看起来像是由加载程序的中心点定位到屏幕最左上角的点:

我可以改变盒子的大小,但我似乎无法将它从左上角移动。此外,我在其上设置了一个动画,该动画会调整帧(从选项卡栏区域上下滑动)。这似乎也没有效果


提前感谢您的帮助。

您的superview就是问题所在。如果要将其添加到UINavigationController中,则y轴可能不会很好地响应。尝试使用控制器的主视图

loaderView.frame = CGRectMake(x, 514, 40, 320);  // made up numbers
[self.mapView addSubview:loaderView];
您还可以访问选项卡栏。尝试使用UIDevice窗口获取宽度并从底部标签继承高度(或将标签嵌套在LoaderView中)


另外,还可以考虑实际使用UITabBar来处理此问题。

您可以轻轻地添加加载查看应用程序窗口。设置loaderView的框架后

[loadView setFrame:CGRectMake(0,0,self.frame.size.width.,self.frame.size.height)];
[self.window addSubview:loaderView];
然后装填完毕

[self.window removeSubview:loaderView];

你的superview是什么级别的?此:[[self-view]addSubview:loaderView];你的例子没有显示任何结果。我确实尝试将视图添加到UITabBar视图中,结果是移动了所述图形,使其中心点指向选项卡栏的左上角,但再次卡住。首先尝试设置选项卡栏的背景色。我已经为您选择了颜色,下面是代码:tabBar.backgroundColor=[UIColor colorWithRed:(46.0/255.0)green:(45.0/255.0)blue:(46.0/255.0)alpha:1.0f];此外,如果您正在使用center,您需要将QuartzCore导入到文件头中,请尝试添加以下内容:#导入,同时确保将其添加到目标>构建阶段>将二进制文件链接到库中。这些都没有帮助。最终需要将加载程序添加到self.tabBar,然后将其推到后面。解决方案即将出台。
[self.window removeSubview:loaderView];