I did a little demo to isolate a problem I faced in a Project.
When I start the Application, the Cells of the NSOutlineView are too narrow for the text:
Then I resize the window with the mouse, making it even narrower than the contents of the NSOutlineView:
When I now enlarge the window again, the problem is cured. From now on the outline works as expected:
This is the main method of my AppDelegate:
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
NSRect frame = NSMakeRect(0., 0., 400., 300.);
NSUInteger styleMask = NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask;
_mainWindow = [[NSWindow alloc] initWithContentRect:frame styleMask:styleMask backing:NSBackingStoreBuffered defer:NO];
_mainWindow.title = #"Outline";
NSScrollView *leftScrollView = [[NSScrollView alloc] init];
leftScrollView.hasVerticalScroller = YES;
leftScrollView.hasHorizontalScroller = NO;
leftScrollView.drawsBackground = NO;
leftScrollView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
_mainWindow.contentView = leftScrollView;
NSOutlineView *outlineView = [[NSOutlineView alloc] init];
NSTableColumn *outlineColumn = [[NSTableColumn alloc] initWithIdentifier:#"Menu Item"];
[outlineView addTableColumn:outlineColumn];
outlineView.outlineTableColumn = outlineColumn;
outlineView.selectionHighlightStyle = NSTableViewSelectionHighlightStyleSourceList;
outlineView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
outlineView.headerView = nil;
_outlineDataSourceAndDelegate = [[MROutlineDataSourceAndDelegate alloc] init];
outlineView.dataSource = _outlineDataSourceAndDelegate;
outlineView.delegate = _outlineDataSourceAndDelegate;
leftScrollView.documentView = outlineView;
[_mainWindow makeKeyAndOrderFront:NSApp];
}
Can anyone please explain that odd behavior?
I don't know whether that is the most elegant solution, but at least it works. I added the following single line after creating the NSTableColumn:
outlineColumn.width = SIDEBAR_WIDTH_DEFAULT;
That's it. Took me almost a day to figure out :(
The answer above was not clean enough for me, so I continued playing around. Now I am pleased: I added a listener to the scroll view that resizes the width of the outline view to be the same as the scroll view. No more need to set the width of the outline column in advance. This is important, if the width is not known in advance.
Related
I am trying to have an animation in which a mask is placed in the center of the view. Any image view that passes behind the mask appears. So here is my code so far, but the problem with this code is that it animates the mask with the image view.
UIView *maskView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.worldImageView.frame.size.height, self.worldImageView.frame.size.height)];
// ...position maskView...
maskView.layer.position = CGPointMake(CGRectGetMidX([self.view bounds]), CGRectGetMidY([self.view bounds]));
maskView.layer.backgroundColor = [UIColor blackColor].CGColor;
maskView.layer.cornerRadius = 90;
self.worldImage = [[UIImageView alloc] init];
self.worldImage.frame = self.worldImageView.frame;
self.worldImage.image = [UIImage imageNamed:#"continents.png"];
[maskView addSubview:self.worldImage];
[self.view addSubview:maskView];
CABasicAnimation* worldAnimation = [[CABasicAnimation alloc] init];
[worldAnimation setFromValue:[NSValue valueWithCGPoint:CGPointMake(self.view.frame.size.width + 50, CGRectGetMidY([maskView bounds]))]];
[worldAnimation setToValue:[NSValue valueWithCGPoint:CGPointMake(-50, CGRectGetMidY([maskView bounds]))]];
worldAnimation.keyPath = #"position";
worldAnimation.duration = 6.0f;
worldAnimation.repeatCount = HUGE_VALF;
[[self.worldImage layer] addAnimation:worldAnimation forKey:nil];
I don't know if I explained this well enough. Please tell me if you need more info. Thank you in advance!
Your issue here is that the mask property of UIView is attached to that UIView - they can't move separately. Technically, it's actually attached to the view's underlying layer, but whatever.
If you want the image to appear as if it's passing in front of a circular window (so that you can see it as it goes by) you'll need to add it as a subview of the view with the mask. So, you might do something like this:
UIView *maskView = [[UIView alloc] init];
// ...position maskView...
maskView.layer.cornerRadius = 90;
maskView.clipsToBounds = YES;
self.worldImage = [[UIImageView alloc] init];
self.worldImage.frame = self.worldImageView.frame;
self.worldImage.image = [UIImage imageNamed:#"continents.png"];
[maskView addSubview:self.worldImage];
[self.view addSubview:maskView];
// ...animate worldImage back and forth...
Note that instead of using a CAShapeLayer, I simply put rounded corners on maskView; since you want a circular mask, it's a much simpler trick. Also, when animating worldImage, consider using one of UIView's block-based animation methods – they're a lot easier to handle for simple stuff like this.
I've been struggling with this for awhile and was hoping anyone could shed some light on why this isn't working.
I'm simply try to implement a Popover on a TableViewCell. Here is the code..
TodoView.m
- (void)tableView:(TUITableView *)tableView didClickRowAtIndexPath:(TUIFastIndexPath *)indexPath withEvent:(NSEvent *)event {
// MyViewController is a TUIViewController with a nib called MyView with just a button in it
MyViewController *t = [[MyViewController alloc] initWithNibName:#"MyView" bundle:nil];
TUIView *theView = [[TUIView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300)];
TUIPopover *myPopover = [[TUIPopover alloc] initWithContentViewController:t];
[myPopover showRelativeToRect:NSMakeRect(0, 0, 300, 300) ofView:theView preferredEdge:NSMaxYEdge];
}
For awhile, nothing would show up. I could tell something was happening though because the window itself would lose focus as if a Popover was there.
Sometimes I see a very small blip– like a small rectangle 2px by 2px. It's hard to see it, looks like dead pixel on the screen, but it appears sometimes when I run this code.
The TUIPopover is from the Twitter UIKit Framework.
Some possibilities...
1) The popover cannot be seen over the CGFillRect?
TodoTableViewCell.m
- (void)drawRect:(CGRect)rect
{
CGRect b = self.bounds;
CGContextRef ctx = TUIGraphicsGetCurrentContext();
CGContextSetRGBFillColor(ctx, 247.0/255, 247.0/255, 247.0/255, 1);
CGContextFillRect(ctx, b);
}
2) The popover doesn't fit inside the TableViewCell and cannot be seen
Anyone have any thoughts?
Really simple answer:
I forgot to set the content size of the popover!
So, for anyone else who is wondering why their popup isn't working, make sure you set the content size!
TUIPopover *p = [[TUIPopover alloc] initWithContentViewController:commentsViewController];
[p setAnimates:TRUE];
[p setContentSize:CGSizeMake(300, 350)];
[p setBehaviour:TUIPopoverViewControllerBehaviourTransient];
[p showRelativeToRect:b.bounds ofView:b preferredEdge:CGRectMinYEdge];
I am trying to center a spinner in the middle of the page using the code below.
self.aSpinner.center = self.view.center;
However when when I run the program, the spinner does not seem to be in the center
Is there any way to fix this?
EDIT:
I found the problem. It's not that the spinner is not in the center, but instead the subview has different bounds than its superview.
I am doing something like this in my code:
self.navcon = [[UINavigationController alloc]init];
self.photoViewTable = [[PhotoTableViewController alloc]init];
self.loadingPage = [[LoadingPageViewController alloc]init];
[self.photoViewTable.view addSubview:loadingPage.view];
[navcon pushViewController:photoViewTable animated:NO];
[self.window addSubview:navcon.view];
How can I set the size of loadingPage view to be equal to the parent view?
[spinner setCenter:CGPointMake(kScreenWidth/2.0, kScreenHeight/2.0)];
Setting the center properties might not be enough. In case your frame is being resize i will also set the autoresize mask of the spinner view:
spinner.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin);
spinner.center = CGPointMake(CGRectGetWidth(self.view.bounds)/2, CGRectGetHeight(self.view.bounds)/2);
Try do it on ViewDidAppear, there is correct self.bounds of view
I don't check self.center.
self.aSpinner.center = CGPointMake(self.view.bounds.width/2.0, self.view.bounds.width/2.0)
Work correct!
Check self has view or self is view
hi I have a problem I made an application based on apples sample app called photoscroller and i want to add a login screen.but when i add it the showed view move upward 10-15 pixels and the main window is visible underneath.I ask why?
Parts of my code:
at view did load:
InfoViewController *infoView = [[InfoViewController alloc] initWithNibName:nil bundle:nil];
self.view = infoView.view;
[infoView release];
then later after validating the login:
CGRect pagingScrollViewFrame = [self frameForPagingScrollView];
pagingScrollView = [[UIScrollView alloc] initWithFrame:pagingScrollViewFrame];
pagingScrollView.pagingEnabled = YES;
pagingScrollView.backgroundColor = [UIColor blackColor];
pagingScrollView.showsVerticalScrollIndicator = NO;
pagingScrollView.showsHorizontalScrollIndicator = NO;
pagingScrollView.contentSize = [self contentSizeForPagingScrollView];
pagingScrollView.delegate = self;
self.view = pagingScrollView;
...
I do not know why is pushed upward when i add other view.
thank for every answer
Could you past the method - (CGRect) frameForPagingScrollView, without that method it's bit harder to understand your code.
But i guess the self.view.frame and the CGRect returned from that method differ.
Further guess would be, that the difference are not 10-15 pixels, but 20 pixels (for the height of the UIStatusBar), which might be enabled in your .xib-File but is actually not displayed.
I have a UIView in a UITabController.
And there is a UITableView in it.
When toggling in call status bar it doesn't do anything and the view is not automatically resized.
It assumes the right size based on whether the in call UIStatusBar was toggled when the app starts but if the UIStatusBar is toggled whilst the app is running nothing changes.
Another tab view with a UINavigationController seems to resize fine.
Here is the code
if ([indexPath indexAtPosition:0] == 0 || [indexPath indexAtPosition:0] == 1) {
if (!airportChooser) {
airportChooser = [[AirportChooserController alloc] init];
airportChooser.targetController = self;
airportChooser.view.autoresizesSubviews = YES;
airportChooser.view.autoresizingMask = UIViewAutoresizingFlexibleHeight;
[airportChooser.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleWidth];
}
airportChooser.target = [indexPath indexAtPosition:0];
[self.parentViewController.parentViewController.view addSubview:airportChooser.view];
self.parentViewController.parentViewController.view.autoresizesSubviews = YES;
self.parentViewController.parentViewController.view.contentMode = UIViewContentModeRedraw;
[self.parentViewController.parentViewController.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleWidth];
airportChooser.view.contentMode = UIViewContentModeRedraw;
//[airportChooser open];
}
Did you set the resizing mask of the UIView correctly? You can set it in Interface Builder in the size tab, it's the red lines that you can click.
You can also set it in code using something like:
[view setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleHeight];
Also make sure the superview has set autoresizesSubviews to YES.
You can find more information about this in the UIView documentation.
Whilst klaaspeiter's answer makes sense and in some cases may be the right answer
in my specific case it was because I was adding a sub view to a UINavigationController's view with addSubview instead of pushViewController:view animated:NO;