0

UIWindow クラスからビューを変更する方法を知りたいです。たとえば、私のアプリにはカウントダウン タイマー ビューがあり、ユーザーがタイマーを開始すると、他の画面に切り替えることができ、タイマーはステータスバーで実行されます。ユーザーがステータスバーをタップすると(ステータスバーの上部にカスタムボタンがあります)、このメソッドが起動され、ビューが現在のビューからタイマーのビューに変更されます...

- (void)statusbarButtonTouched
{

    NSLog(@"Button TOuched");

    [self addSubview:??]

}
4

2 に答える 2

0

ドキュメントに従って

- (void)removeFromSuperview

レシーバーをそのスーパービューとそのウィンドウからリンク解除し、レスポンダー チェーンから削除します。

于 2013-04-24T05:11:27.917 に答える
0

timerView定義済みのプロパティを使用して App デリゲートで作成します。

AppDelegate.h

@property (nonatomic, retain) UIView *timerView;

AppDelegate.m

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    self.viewController = [[[FLViewController alloc] initWithNibName:@"FLViewController" bundle:nil] autorelease];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];


    self.timerView = [[UIView alloc] initWithFrame:self.window.frame];
    [self.timerView setBackgroundColor:[UIColor greenColor]];
    [self.window addSubview:self.timerView];
    [self.timerView setHidden:YES];


    return YES;
}

このビューを前面に表示するコード:

- (IBAction)shouTimerViewTouched:(id)sender {
    AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [delegate.timerView setHidden:NO];
    [delegate.window bringSubviewToFront:delegate.timerView];
}

それでおしまい。https://github.com/rptwshi/TrickTestからデモを実行するためにプルできます。

乾杯。

于 2013-04-24T06:51:51.177 に答える