2

ウィンドウにサブビュー (ルート ViewController のビュー) が追加されます。

このようなサブビューは、他のいくつかのサブビューのスーパービューです。

アプリを完成させたばかりで、広告を追加したいと考えています。

ここにいくつかのコードがあります:

[window addSubview:viewController.view];
viewController.view.frame=CGRectMake(0,0,320,480-48);
viewController.clipToBounds=YES;
Ad *ad=[Ad alloc] initWithFrame:CGRectMake(0,480-48,320,48)];

上記のviewControllerにはいくつかのサブビューがありますが、サイズは変更されません。上記の viewController.view はもともと 320,480 で、下部の最後のピクセルまでサブビューで完全に埋められていました。高さを 480 から 460 に変更した後、サブビューのサイズが変更されないため、ビューの下部 (広告が表示される場所) にいくつかのサブビューが表示されません。

サブビューのサイズを変更して、親ビュー (viewController.view) の高さが 20px 縮小されている場合、親ビュー (viewController.view) に合わせてサイズを変更するにはどうすればよいですか? (多少変形することは承知しております)

4

2 に答える 2

8

サブビューの自動サイズ変更マスクを設定する必要があります。

ad.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

詳細については、UIView のドキュメントを参照してください。

于 2010-09-11T00:35:29.707 に答える
0

この投稿はほとんど役に立ちました。私は最終的に、いくつかのインターネット ソースと、数時間頭をかきむしったり遊んだりして、それを機能させるようにしました。ここのブログに書きました:http://workingmatt.blogspot.co.uk/2014/08/xcode-5-quartz-composer-bug-fix.html

しかし、便宜上、ここに重要なビットがあります...

DisplayController.h

#import <Quartz/Quartz.h>
@interface DisplayController : NSObject
{
  __strong QCView * qcView;
  QCCompositionParameterView *qcParamsView;
}

@property (unsafe_unretained) IBOutlet NSWindow *displayWindow;
@property (unsafe_unretained) IBOutlet NSWindow *displaySettings;
@property (strong) IBOutlet QCCompositionParamterView *paramsView;
@end

DisplayController.m

@synthesize qcView;
@synthesize qcParamsView;

- (void) awakeFromNib
{
  NSString *path = [[NSBundle mainBundle] pathForResource:@"Luna Vertical2014" ofType:@"qtz"];
  NSView *superView = [self.displayWindow contentView];
  qcView = [[QCView alloc] initWithFrame:superView.frame];
  [superView addSubview:qcView];
  [superView setTranslatesAutoresizingMaskIntoConstraints:YES];
  [superView setAutoresizesSubviews:YES];
  [qcView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];

  [superView addConstraint:
   [NSLayoutConstraint constraintWithItem: qcView
                                attribute: NSLayoutAttributeWidth
                                relatedBy: NSLayoutRelationEqual
                                   toItem: superView
                                attribute: NSLayoutAttributeWidth
                               multiplier: 1
                                 constant: 0]];

  [superView addConstraint:
   [NSLayoutConstraint constraintWithItem: qcView
                                attribute: NSLayoutAttributeHeight
                                relatedBy: NSLayoutRelationEqual
                                   toItem: superView
                                attribute: NSLayoutAttributeHeight
                               multiplier: 1
                                 constant: 0]];
  [superView addConstraint:
   [NSLayoutConstraint constraintWithItem: qcView
                                attribute: NSLayoutAttributeCenterX
                                relatedBy: NSLayoutRelationEqual
                                   toItem: superView
                                attribute: NSLayoutAttributeCenterX
                               multiplier: 1
                                 constant: 0]];
  [superView addConstraint:
   [NSLayoutConstraint constraintWithItem: qcView
                                attribute: NSLayoutAttributeCenterY
                                relatedBy: NSLayoutRelationEqual
                                   toItem: superView
                                attribute: NSLayoutAttributeCenterY
                               multiplier: 1
                                 constant: 0]];

  [qcView unloadComposition];
  [qcView loadCompositionFromFile:path];
  [qcView setMaxRenderingFrameRate: 30.0];
  [qcView startRendering];

  if(![qcView loadCompositionFromFile:path])
  {
      NSLog(@"QC Composition failed to load");
      [NSApp terminate:nil];
  }
  NSLog(@"QC Composition has been loaded!!!!");
  NSLog(@"inputKeys: %@", qcView.inputKeys);

  //Create a parameters view
    //Note that a new referencing outlet was added from
    //Display Settings window to DisplayController
    //by dragging the round circle on the far left over 
    //to the blue cube in the xib.
    //Check out displaycontroller.h and .m

  NSView *paramsSuperView = [self.displaySettings contentView];
  qcParamsView = [[QCCompositionParameterView alloc] initWithFrame:paramsSuperView.frame];
  [paramsSuperView addSubview:qcParamsView];
  [paramsSuperView setTranslatesAutoresizingMaskIntoConstraints:YES];
  [paramsSuperView setAutoresizesSubviews:YES];
  [qcParamsView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
  [qcParamsView setCompositionRenderer:qcView];

    // If you need mouse/keyboard interaction with QC uncomment this line
    //    qcView.eventForwardingMask = NSAnyEventMask;
}
于 2014-08-28T19:39:10.267 に答える