• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Subview and window size
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Subview and window size


  • Subject: Re: Subview and window size
  • From: Mike Abdullah <email@hidden>
  • Date: Sat, 19 Dec 2009 15:38:55 +0000

On 18 Dec 2009, at 13:36, Graham Cox wrote:

>
> On 19/12/2009, at 12:14 AM, Kevin Walzer wrote:
>
>> I am trying add a subview to an NSView programatically, and am having some difficulty.
>>
>> Here's my code:
>> DNDView *dropview = [[DNDView alloc] init];
>
>
> This is wrong. The designated initializer for NSView is -initWithFrame:

This is quite acceptable. Being the designated initializer does not mean that your code _must_ call a method. It means that the designated initializer will always be called at some point during initialization. And so, if you are subclassing, that is the method to override.

Unless the documentation calls it out, calling -init on a view is generally acceptable. It will be initialised with some kind of default frame. Of course, what that frame is could be anything unless explicitly documented!
>
>
>> NSView *view;
>> if ([dropview superview] != view) {
>>   [view addSubview:dropview positioned:NSWindowBelow relativeTo:nil];
>> }
>>
>> NSRect frame = [dropview frame];
>> NSRect parentframe = [view frame];
>> frame.size.width = parentframe.size.width;
>> frame.size.height = parentframe.size.height;
>> [dropview setFrame:frame];
>>
>> [dropview displayRectIgnoringOpacity:[dropview bounds]]
>>
>> The *view is supposed to take up the entire window, and my idea is to have the subview do so, as well. However, when I add the subview DNDView (which is supposed to be registered to receive file drags), it does not take up the whole window--it takes up approximately 1/4th of the window.
>>
>> How can I get the subview to be the same size as its parent view?
>
> It is the same size, it's just not in the right place, is my guess.
>
> Use the correct initializer and pass it the frame you want up front, then just add the subview. There's also no reason to call -displayRectIgnoringOpacity, the view will get drawn on the next cycle as normal.

But yes, it is easier to call -initWithFrame: to begin with. And then is no need to call -displayRectIgnoringOpacity:_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Subview and window size (From: Kevin Walzer <email@hidden>)
 >Re: Subview and window size (From: Graham Cox <email@hidden>)

  • Prev by Date: Re: NSAttributedString fill with gradient
  • Next by Date: Re: Detecting system protected folders.
  • Previous by thread: Re: Subview and window size
  • Next by thread: Re: Subview and window size
  • Index(es):
    • Date
    • Thread