• 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: Auto-Layout Strangeness
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Auto-Layout Strangeness


  • Subject: Re: Auto-Layout Strangeness
  • From: Dave <email@hidden>
  • Date: Wed, 30 Jul 2014 21:57:13 +0100

Hi,

> But your mentioning of background color is kind of strange, since that should be set regardless of -drawRect: being called – or are you doing things unrelated to drawing inside of -drawRect:?

No, here is the method.:


-(void) drawRect:(CGRect) theRect
{
CGRect					myRect;
CGContextRef			myGraphicContext;
UIColor*				myFrameColor;

if (self.pDrawFrameFlag == NO)
	return;

myRect = CGRectInset(theRect,0,0);
myFrameColor = [UIColor blackColor];
myGraphicContext = UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(myGraphicContext,[myFrameColor CGColor]);
CGContextSetLineWidth(myGraphicContext,3);
CGContextStrokeRect(myGraphicContext,myRect);
}

I tried forcing setNeedsDisplay and Yes,  the backgroundColor not being set is very strange.

The initWithCoder method is called for it, just the background doesn’t get set and drawRect does’t get called.

> -drawRect: is driven by -setNeedDisplay, which is driven by things such as frame changes. The likely difference in your scenarios is simply that the frame isn’t changing.


Do you mean between having Auto-layout on or off, or between adding a new subview?

I’m not sure if you saw my follow up, if I add a subview that is the same size and position and the “DrawFrame” view, and put “DrawFrame” and all it’s subviews inside this new view, it it works as expected. It looks like the first subview just isn’t being handling correctly if auto layout is off.

Thanks for taking the time to reply.

All the Best
Dave


On 30 Jul 2014, at 20:46, David Duncan <email@hidden> wrote:

>
>> On Jul 30, 2014, at 10:18 AM, Dave <email@hidden> wrote:
>>
>> XCode 5, Mac OS 10.9.4, iOS 7.
>>
>> Hi,
>>
>> I'm working on a project that uses a lot of view “cells” that go into Scroll and Table Views. Each “cell” View is in separate .xib file and is loaded something like this:
>>
>> +(instancetype) newViewOfKind:(NSString*) theViewKind withItemInfo:(LTWItemInfo*) theItemInfo
>> {
>> NSString*	myClassName;
>> LTWItemView*	myNewCell;
>>
>> myClassName = NSStringFromClass([self class]);
>> myNewCell = [[super class] newViewOfKind:theViewKind withItemInfo:theItemInfo andNIBBaseName:myClassName];
>>
>> if (myNewCell.pItemActivityIndicator != nil)
>> 	myNewCell.pItemActivityIndicator.hidesWhenStopped = YES;
>>
>> myNewCell.pItemDownloadImageLoadedFlag = NO;
>> myNewCell.pItemDownloadImage = nil;
>> [myNewCell setItemInfo:theItemInfo];
>>
>> return myNewCell;
>> }
>>
>>
>> This works well and is being used in lots of places in the App.
>>
>> This project was originated before Auto-Layout was around and it is off in all the cell .xib files.
>>
>> The .xib file for each of these views has a “standard” layout that looks like this:
>>
>> LTWItemView.xib   — Auto-Layout off.
>>
>> LTWItemView
>> 	“FrameRect” - View of Class “LTWDrawFrameView” Inside LTWItemView above  (this is a normal view, but drawRect overridden to draw a frame around the view).
>>   	       Inside the “FrameRect” view, other views UILabels, UIImageView’s, UIButton’s, etc.
>>
>> The problem is that the drawRect method in “FrameRect” does not get called and it’s background colour doesn’t get set either. When I first created this view, I had Auto-Layout enabled and in this case the background colour is set ok and the drawRect is called.
>
> -drawRect: is driven by -setNeedDisplay, which is driven by things such as frame changes. The likely difference in your scenarios is simply that the frame isn’t changing. But views when created are also set to need to be drawn, so I would expect it to be called at least once when coming from the nib.
>
> But your mentioning of background color is kind of strange, since that should be set regardless of -drawRect: being called – or are you doing things unrelated to drawing inside of -drawRect:?
>
>>
>> The problem is that if I enabled Auto-Layout, it causes problems elsewhere and it’s too big a job to convert the project to use it.
>>
>> Any ideas on how to solve this would be greatly appreciated.
>>
>> Thanks a lot
>> Dave
>>
>> _______________________________________________
>>
>> 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
>
> --
> David Duncan
>


_______________________________________________

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


  • Follow-Ups:
    • Re: Auto-Layout Strangeness
      • From: Graham Cox <email@hidden>
References: 
 >Auto-Layout Strangeness (From: Dave <email@hidden>)
 >Re: Auto-Layout Strangeness (From: David Duncan <email@hidden>)

  • Prev by Date: Re: ARC and NSObjectController bindings through file's owner
  • Next by Date: Re: How to get the time zone of a parsed date/time string?
  • Previous by thread: Re: Auto-Layout Strangeness
  • Next by thread: Re: Auto-Layout Strangeness
  • Index(es):
    • Date
    • Thread