Keep UIView fixed when attached to UIWindow in iOS8 - objective-c

Up until iOS7, if I wanted to create a sort of a fixed "background" that would not rotate, animate or scale whatsoever, I would have simply attached a UIView to the main UIWindow.
It was a kind of hack... but it served very well its purpose.
In iOS8 they changed the way UIWindow behave among other things (for example now [UIScreen mainScreen].bounds returns different size depending on the orientation).
Anyway...
My question is: how do I get iOS8 to behave as iOS7 and below?
I tried already to create two ViewControllers, one with shouldAutorotate method set to NO but with no luck.
The desired effect is the one shown here:
Any ideas?

If you build your app using iOS8 SDK, you can use nativeBounds, which will always return bounds for portrait orientation, but in the pixels, not in the points.
To get right bounds in points you should divide them by nativeScale.
if ([[UIScreen mainScreen] respondsToSelector:#selector(nativeBounds)]) {
CGFloat scaleFactor = 1.0f / [self nativeScale];
CGRect realBounds = CGRectApplyAffineTransform([self nativeBounds],
CGAffineTransformMakeScale(scaleFactor, scaleFactor));
}
So I think you can subscribe to didChangeStatusBarOrientation notification and in your method calculate new frame for green square and justify rotation:
rect.transform = CGAffineTransformMakeRotation((CGFloat)M_PI * (90.f) / 180.0f);
for landscape right orientation

try to use this subclass with fixed rotation:
#interface RotationView : UIView {
struct {
CGPoint portOrigin;
CGPoint leftOrigin;
CGPoint rightOrigin;
CGPoint upsideOrigin;
} origins;
struct {
NSInteger portDegree;
NSInteger leftDegree;
NSInteger rightDegree;
NSInteger upsideDegree;
} degrees;
}
#end
#implementation RotationView
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(deviceOrientationDidChange:)
name:UIDeviceOrientationDidChangeNotification object:nil];
}
return self;
}
- (void)didMoveToSuperview {
[super didMoveToSuperview];
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (orientation == UIInterfaceOrientationPortrait) {
origins.portOrigin = self.frame.origin;
origins.rightOrigin = CGPointMake(CGRectGetMinY(self.frame), CGRectGetWidth(self.superview.frame) - CGRectGetMinX(self.frame) - CGRectGetWidth(self.frame));
origins.leftOrigin = CGPointMake(CGRectGetHeight(self.superview.frame) - CGRectGetMinY(self.frame) - CGRectGetHeight(self.frame), CGRectGetMinX(self.frame));
origins.upsideOrigin = CGPointMake(CGRectGetWidth(self.superview.frame) - CGRectGetMinX(self.frame) - CGRectGetWidth(self.frame),
CGRectGetHeight(self.superview.frame) - CGRectGetMinY(self.frame) - CGRectGetHeight(self.frame));
degrees.portDegree = 0.0F;
degrees.rightDegree = 270;
degrees.leftDegree = 90.0F;
degrees.upsideDegree = 180.0F;
} else if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
origins.portOrigin = CGPointMake(CGRectGetWidth(self.superview.frame) - CGRectGetMinX(self.frame) - CGRectGetWidth(self.frame),
CGRectGetHeight(self.superview.frame) - CGRectGetMinY(self.frame) - CGRectGetHeight(self.frame));
origins.leftOrigin = CGPointMake(CGRectGetMinY(self.frame), CGRectGetWidth(self.superview.frame) - CGRectGetMinX(self.frame) - CGRectGetWidth(self.frame));
origins.rightOrigin = CGPointMake(CGRectGetHeight(self.superview.frame) - CGRectGetMinY(self.frame) - CGRectGetHeight(self.frame), CGRectGetMinX(self.frame));
origins.upsideOrigin = self.frame.origin;
degrees.portDegree = 180.0F;
degrees.rightDegree = 90.0F;
degrees.leftDegree = 270;
degrees.upsideDegree = 0.0F;
} else if (orientation == UIInterfaceOrientationLandscapeLeft) {
origins.upsideOrigin = CGPointMake(CGRectGetHeight(self.superview.frame) - CGRectGetMinY(self.frame) - CGRectGetHeight(self.frame), CGRectGetMinX(self.frame));
origins.leftOrigin = self.frame.origin;
origins.rightOrigin = CGPointMake(CGRectGetWidth(self.superview.frame) - CGRectGetMinX(self.frame) - CGRectGetWidth(self.frame),
CGRectGetHeight(self.superview.frame) - CGRectGetMinY(self.frame) - CGRectGetHeight(self.frame));
origins.portOrigin = CGPointMake(CGRectGetMinY(self.frame), CGRectGetWidth(self.superview.frame) - CGRectGetMinX(self.frame) - CGRectGetWidth(self.frame));
degrees.upsideDegree = 90.0F;
degrees.leftDegree = 0.0F;
degrees.rightDegree = 180.0F;
degrees.portDegree = 270.0;
} else if (orientation == UIInterfaceOrientationLandscapeRight) {
origins.portOrigin = CGPointMake(CGRectGetHeight(self.superview.frame) - CGRectGetMinY(self.frame) - CGRectGetHeight(self.frame), CGRectGetMinX(self.frame));
origins.leftOrigin = CGPointMake(CGRectGetWidth(self.superview.frame) - CGRectGetMinX(self.frame) - CGRectGetWidth(self.frame),
CGRectGetHeight(self.superview.frame) - CGRectGetMinY(self.frame) - CGRectGetHeight(self.frame));
origins.rightOrigin = self.frame.origin;
origins.upsideOrigin = CGPointMake(CGRectGetMinY(self.frame), CGRectGetWidth(self.superview.frame) - CGRectGetMinX(self.frame) - CGRectGetWidth(self.frame));
degrees.portDegree = 90.0F;
degrees.leftDegree = 180.0F;
degrees.rightDegree = 0.0F;
degrees.upsideDegree = 270.0F;
}
}
#pragma mark Manual oritentation change
#define RADIANS(degrees) ((degrees * (float)M_PI) / 180.0f)
- (void)deviceOrientationDidChange:(NSNotification *)notification {
if (!self.superview) {
return;
}
if ([self.superview isKindOfClass:[UIWindow class]]) {
[self setTransformForCurrentOrientation];
}
}
- (void)setTransformForCurrentOrientation {
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (UIInterfaceOrientationIsLandscape(orientation)) {
if (orientation == UIInterfaceOrientationLandscapeLeft) {
[self setTransform:CGAffineTransformMakeRotation(RADIANS(degrees.leftDegree))];
[self setOrigin:origins.leftOrigin];
} else {
[self setTransform:CGAffineTransformMakeRotation(RADIANS(degrees.rightDegree))];
[self setOrigin:origins.rightOrigin];
}
} else {
if (orientation == UIInterfaceOrientationPortraitUpsideDown) {
[self setTransform:CGAffineTransformMakeRotation(RADIANS(degrees.upsideDegree))];
[self setOrigin:origins.upsideOrigin];
} else {
[self setTransform:CGAffineTransformMakeRotation(RADIANS(degrees.portDegree))];
[self setOrigin:origins.portOrigin];
}
}
}
#end
setOrigin is category method:
- (void)setX:(CGFloat)x {
CGRect frame = self.frame;
frame.origin.x = x;
self.frame = frame;
}
- (void)setY:(CGFloat)y {
CGRect frame = self.frame;
frame.origin.y = y;
self.frame = frame;
}
- (void)setOrigin:(CGPoint)origin {
[self setX:origin.x];
[self setY:origin.y];
}

Related

How to receive mouseDown messages in a NSTableViewCell?

I am trying to make a table view cell that shows ratings for songs in a playlist. I have successfully created the cell so that it shows the current number of stars, and also an indication of how a new setting will be when you hover your mouse cursor over a cell to give a new rating.
The problem is that while mouseEnter, mouseExit and mouseMove works like a charm, I get no messages for mouseDown, which is required to actually change the value of the cell.
I have searched all over the Internet, but I can't find any solution to how to solve this problem anywhere. I have spent so many hours trying to sort this. I hope anyone have any answer or hint what I can do. Thank you.
The full code for the current implementation is as follows:
#import "FavouriteCellView.h"
#implementation FavouriteCellView {
NSTrackingArea *_trackingArea;
int _starsRated; //The current rating value
BOOL _hovering; //YES if the mouse is currently hovering over this cell
int _starsHovering; //The number of stars hovering, if the mouse is hovering over this cell
}
- (void)awakeFromNib {
[super awakeFromNib];
_starsRated = 1;
_hovering = NO;
_starsHovering = 0;
[self createTrackingArea];
}
- (void)createTrackingArea
{
_trackingArea = [[NSTrackingArea alloc] initWithRect:self.bounds options:NSTrackingMouseEnteredAndExited |NSTrackingActiveInActiveApp | NSTrackingMouseMoved owner:self userInfo:nil];
[self addTrackingArea:_trackingArea];
}
- (void)updateTrackingAreas{
[self removeTrackingArea:_trackingArea];
_trackingArea = nil;
[self createTrackingArea];
}
- (void)drawRect:(NSRect)dirtyRect {
[super drawRect:dirtyRect];
// CGFloat middleX = [self bounds].size.width / 2.0f;
CGFloat middleY = [self bounds].size.height / 2.0f;
CGFloat starDivs = [self bounds].size.width / 5.0f;;
NSColor *starSelectedColor = [NSColor colorWithDeviceRed:0.8f green:0.0f blue:0.4f alpha:1.0f];
NSColor *starUnselectedColor = [NSColor colorWithDeviceRed:0.5f green:0.5f blue:0.5f alpha:1.0f];
NSColor *starHoverColor = [NSColor colorWithDeviceRed:1.0f green:0.843f blue:0.0f alpha:1.0f];
NSColor *starHoverColorSelected = [NSColor colorWithDeviceRed:0.9f green:0.843f blue:0.6f alpha:1.0f];
for (int i = 0; i < 5; i++) {
NSColor *useColor = [NSColor redColor];
if (_hovering && (i <= _starsHovering)) {
if (i <= _starsRated) {
useColor = starHoverColorSelected;
} else {
useColor = starHoverColor;
}
} else if (i <= _starsRated) {
useColor = starSelectedColor;
} else {
useColor = starUnselectedColor;
}
[self star:NSMakePoint((starDivs / 2.0f) + starDivs * i, middleY) color:useColor];
}
}
-(void)star:(NSPoint)center color:(NSColor *)color {
[color set];
CGFloat t = (2.0f * M_PI) / 10.0f;
NSBezierPath *path = [[NSBezierPath alloc] init];
CGFloat radii1 = 12.0f;
CGFloat radii2 = 4.0f;
CGFloat rot = M_PI / 2.0f;
BOOL first = YES;
for (int i = 0; i < 10; i++) {
CGFloat pointX = cos(t * i + rot) * radii1 + center.x;
CGFloat pointY = sin(t * i + rot) * radii1 + center.y;
CGFloat tempRadii = radii1;
radii1 = radii2;
radii2 = tempRadii;
if (first) {
first = NO;
[path moveToPoint:NSMakePoint(pointX, pointY)];
}
else {
[path lineToPoint:NSMakePoint(pointX, pointY)];
}
}
[path closePath];
[path fill];
/*
[[NSColor blackColor] set];
[path setLineWidth:0.25f];
[path stroke];
*/
}
-(NSView *)hitTest:(NSPoint)aPoint {
//THIS GETS CALLED
return self;
}
-(BOOL)validateProposedFirstResponder:(NSResponder *)responder forEvent:(NSEvent *)event {
printf("$"); //DOES NOT GET CALLED
return YES;
}
-(BOOL)acceptsFirstResponder {
printf("!"); //DOES NOT GET CALLED
return YES;
}
-(BOOL)acceptsFirstMouse:(NSEvent *)theEvent {
printf("8"); //DOES NOT GET CALLED
return YES;
}
-(void)mouseDown:(NSEvent *)theEvent {
printf("o"); //DOES NOT GET CALLED
_starsRated = _starsHovering;
}
-(void)mouseUp:(NSEvent *)theEvent {
printf("O"); //DOES NOT GET CALLED
}
-(void)mouseEntered:(NSEvent *)theEvent {
//DOES GET CALLED
_hovering = YES;
[self setNeedsDisplay:YES];
}
-(void)mouseExited:(NSEvent *)theEvent {
//DOES GET CALLED
_hovering = NO;
[self setNeedsDisplay:YES];
}
-(void)mouseMoved:(NSEvent *)theEvent {
//DOES GET CALLED
NSPoint mouseLocation = [[self window] mouseLocationOutsideOfEventStream];
mouseLocation = [self convertPoint: mouseLocation
fromView: nil];
int newStarsHoveringValue = mouseLocation.x / ([self bounds].size.width / 5.0f);
if (newStarsHoveringValue != _starsHovering) {
_starsHovering = newStarsHoveringValue;
[self setNeedsDisplay:YES];
}
}
#end
It was a bit fiddly, but I managed to create a solution that works. I subclassed NSTableView, then overrode mouseDown with the following code:
-(void)mouseDown:(NSEvent *)theEvent {
NSPoint globalLocation = [theEvent locationInWindow];
NSPoint localLocation = [self convertPoint:globalLocation fromView:nil];
NSInteger clickedRow = [self rowAtPoint:localLocation];
if (clickedRow != -1) {
NSInteger clickedColumn = [self columnAtPoint:localLocation];
if (clickedColumn != -1) {
if (clickedColumn == 3) {
FavouriteCellView *fv = [self viewAtColumn:clickedColumn row:clickedRow makeIfNecessary:NO];
if (fv != nil) {
[fv mouseDown:theEvent];
}
return;
}
}
}
[super mouseDown:theEvent];
}
Now it works exactly like I wanted.

UIPinchGestureRecognizer trouble

Ok, i've read a few posts on this one (ex. UIImageView Gestures (Zoom, Rotate) Question) but I can't seem to fix my problem.
I have the following setup: an SKScene, an SKNode _backgroundLayer and 9 SKSpriteNodes that are tiles that make up the background and are attached to the _backgroundLayer.
Since these 9 tiles make a 3x3 square and they are quite large, I need to be able to zoom in and look at other SKSpriteNodes that will be on top of these 9 background images.
There are two problems:
1) When I pinch to zoom in or zoom out it seems like it is zooming in/out from location (0,0) of the _backgroundLayer and not from the touch location.
2) I have added some bounds so that the user can not scroll out of the 9 background images. In general it works. However, if I zoom in then move towards the top of the 9 background images and then zoom out the bounding conditions go berserk and the user can see the black space outside the background images. I need a way to limit the amount of zooming out that the user can do depending on where he's at.
Any ideas? Thanks!
I include my code below:
#import "LevelSelectScene.h"
#import "TurtleWorldSubScene.h"
#interface LevelSelectScene ()
#property (nonatomic, strong) SKNode *selectedNode;
#end
#implementation LevelSelectScene
{
SKNode *_backgroundLayer;
}
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
/* Setup your scene here */
_backgroundLayer = [SKNode node];
_backgroundLayer.name = #"backgroundLayer";
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
[_backgroundLayer setScale:0.76];
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && IS_WIDESCREEN) {
} else {
[_backgroundLayer setScale:0.36];
}
[self addChild:_backgroundLayer];
SKTexture *backgroundTexture = [SKTexture textureWithImageNamed:#"levelSelect"];
int textureID = 0;
for (int i = 0; i<3; i++) {
for (int j = 0; j<3; j++) {
SKSpriteNode *background = [SKSpriteNode spriteNodeWithTexture:backgroundTexture];
background.anchorPoint = CGPointZero;
background.position = CGPointMake((background.size.width)*i, (background.size.height)*j);
background.zPosition = 0;
background.name = [NSString stringWithFormat:#"background%d", textureID];
textureID++;
[_backgroundLayer addChild:background];
}
}
[TurtleWorldSubScene displayTurtleWorld:self];
}
return self;
}
- (void)didMoveToView:(SKView *)view {
UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(handlePanFrom:)];
[[self view] addGestureRecognizer:panGestureRecognizer];
//UITapGestureRecognizer * tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleTap:)];
// [self.view addGestureRecognizer:tapRecognizer];
UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:#selector(handlePinch:)];
[[self view] addGestureRecognizer:pinchGestureRecognizer];
}
- (void)handlePanFrom:(UIPanGestureRecognizer *)recognizer {
if (recognizer.state == UIGestureRecognizerStateBegan) {
CGPoint touchLocation = [recognizer locationInView:recognizer.view];
touchLocation = [self convertPointFromView:touchLocation];
SKNode *node = [self nodeAtPoint:touchLocation];
_selectedNode = node;
} else if (recognizer.state == UIGestureRecognizerStateChanged) {
CGPoint translation = [recognizer translationInView:recognizer.view];
translation = CGPointMake(translation.x, -translation.y);
CGPoint initialPosition = CGPointAdd(_backgroundLayer.position, translation);
_backgroundLayer.position = [self boundLayerPos:initialPosition];
[recognizer setTranslation:CGPointZero inView:recognizer.view];
} else if (recognizer.state == UIGestureRecognizerStateEnded) {
float scrollDuration = 0.2;
CGPoint velocity = [recognizer velocityInView:recognizer.view];
CGPoint pos = [_backgroundLayer position];
CGPoint p = CGPointMultiplyScalar(velocity, scrollDuration);
CGPoint newPos = CGPointMake(pos.x + p.x, pos.y - p.y);
newPos = [self boundLayerPos:newPos];
[_backgroundLayer removeAllActions];
SKAction *moveTo = [SKAction moveTo:newPos duration:scrollDuration];
[moveTo setTimingMode:SKActionTimingEaseOut];
[_backgroundLayer runAction:moveTo];
}
}
- (void)handlePinch:(UIPinchGestureRecognizer *) recognizer
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
if(_backgroundLayer.xScale*recognizer.scale < 0.76) {
//SKSpriteNode *backgroundTile = (SKSpriteNode *)[_backgroundLayer childNodeWithName:#"background0"];
[_backgroundLayer setScale:0.76];
} else if(_backgroundLayer.xScale*recognizer.scale > 2) {
[_backgroundLayer setScale:2.0];
} else {
[_backgroundLayer runAction:[SKAction scaleBy:recognizer.scale duration:0]];
}
} else if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && IS_WIDESCREEN) {
} else {
if(_backgroundLayer.xScale*recognizer.scale < 0.36) {
[_backgroundLayer setScale:0.36];
} else if(_backgroundLayer.xScale*recognizer.scale > 2) {
[_backgroundLayer setScale:2.0];
} else {
[_backgroundLayer runAction:[SKAction scaleBy:recognizer.scale duration:0]];
}
}
recognizer.scale = 1;
}
- (CGPoint)boundLayerPos:(CGPoint)newPos {
SKSpriteNode *backgroundTile = (SKSpriteNode *)[_backgroundLayer childNodeWithName:#"background0"];
CGPoint retval = newPos;
retval.x = MIN(retval.x, 0);
retval.x = MAX(retval.x, -(backgroundTile.size.width*_backgroundLayer.xScale*3)+self.size.width);
retval.y = MIN(retval.y, 0);
retval.y = MAX(retval.y, -(backgroundTile.size.height*_backgroundLayer.xScale*3)+self.size.height);
return retval;
}

How to set scrollView with minimal scale at start?

I have to set UIScrollView at start with 0.28 scale (current scale). How can i do it correclty?
Now to scaling I'm using this methods:
#pragma mark - UIScrollViewDelegate Methods
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return imageView;
}
-(void)scrollViewDidZoom:(UIScrollView *)scrollView {
[self centerScrollViewContent];
}
-(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
}
- (void)centerScrollViewContent {
CGSize boundsSize = self.scrollView.bounds.size;
CGRect contentsFrame = imageView.frame;
if (contentsFrame.size.width < boundsSize.width) {
contentsFrame.origin.x = (boundsSize.width - contentsFrame.size.width) / 2.0f;
} else {
contentsFrame.origin.x = 0.0f;
}
if (contentsFrame.size.height < boundsSize.height) {
contentsFrame.origin.y = (boundsSize.height - contentsFrame.size.height) / 2.0f;
} else {
contentsFrame.origin.y = 0.0f;
}
imageView.frame = contentsFrame;
}
After your scrollView content is loaded, you can set the zoom scale with:
self.scrollView.zoomScale = 0.28;

How to center UIImageView in ScrollView (Zooming)

I'm trying to zooming UIImageView in UIScrollView. And i've got this:
-(UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return imageView;
}
-(void)scrollViewDidZoom:(UIScrollView *)scrollView {
[imageView setCenter:CGPointMake(scrollView.center.x, scrollView.center.y)];
}
-(void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
}
Problem is: When i'm zooming out image it's centered, but when i'm zooming in, image is shifted to left up corner.
Where is problem with my code?
Answer is remove all from scrollViewDidZoom: and add:
[self centerScrollViewContent];
Method implementation:
- (void)centerScrollViewContents {
CGSize boundsSize = self.scrollView.bounds.size;
CGRect contentsFrame = self.containerView.frame;
if (contentsFrame.size.width < boundsSize.width) {
contentsFrame.origin.x = (boundsSize.width - contentsFrame.size.width) / 2.0f;
} else {
contentsFrame.origin.x = 0.0f;
}
if (contentsFrame.size.height < boundsSize.height) {
contentsFrame.origin.y = (boundsSize.height - contentsFrame.size.height) / 2.0f;
} else {
contentsFrame.origin.y = 0.0f;
}
self.containerView.frame = contentsFrame;
}

How to get title of NSButtonCell in delegate method of NSOutlineView

I am using NSButtonCell subclass to display checkbox , image and label in same cell. Now i want to edit label in outlineView on double click or on enter key.
NSButtonCell subclass:
- (void)dealloc {
[image release];
image = nil;
[super dealloc];
}
-(id)copyWithZone:(NSZone *)zone {
ImageAndTextAndCheckBox *cell = (ImageAndTextAndCheckBox *)[super copyWithZone:zone];
cell->image = [image retain];
return cell;
}
- (void)setImage:(NSImage *)anImage {
if (anImage != image) {
[image release];
image = [anImage retain];
[image setSize:NSMakeSize(kIconImageSize, kIconImageSize)];
}
}
- (NSImage *)image {
return image;
}
#define KNImageAndTextButtonCellPadding 5 // Distance between the end of the image and the start of the text.
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
// Draw the original button first, then the image.
//shift check box to right
NSRect newCellFrame = cellFrame;
newCellFrame.origin.x = newCellFrame.origin.x + 5;
cellFrame = newCellFrame;
[super drawWithFrame:cellFrame inView:controlView];
if (image != nil) {
NSRect imageFrame;
NSSize imageSize = [image size];
NSDivideRect(cellFrame, &imageFrame, &cellFrame, KNImageAndTextButtonCellPadding + imageSize.width, NSMinXEdge);
imageFrame.origin.x += imageFrame.size.width;
imageFrame.size = imageSize;
if ([controlView isFlipped]) {
imageFrame.origin.y += ceil((cellFrame.size.height + imageFrame.size.height) / 2);
} else {
imageFrame.origin.y += ceil((cellFrame.size.height - imageFrame.size.height) / 2);
}
BOOL oldFlipped = [image isFlipped];
[image setFlipped:![controlView isFlipped]];
[image compositeToPoint:imageFrame.origin operation:NSCompositeSourceOver];
[image setFlipped:oldFlipped];
}
}
-(BOOL)trackMouse:(NSEvent *)theEvent inRect:(NSRect)cellFrame ofView:(NSView *)controlView untilMouseUp:(BOOL)untilMouseUp {
// Make sure that the mouse only gets tracked if it is clicked on the check box, otherwise
// the row will be checked/unchecked whenever the user clicks on any part of the cell (which is bad).
if ([theEvent clickCount] > 1)
{
NSLog(#"do double-click action" );
}
else
{
NSLog(#"do single-click action" );
}
NSPoint event_location = [theEvent locationInWindow];
NSPoint localPoint = [controlView convertPoint:event_location fromView:nil];
//shift check box mouse event to right
NSRect newCellFrame = cellFrame;
newCellFrame.origin.x = newCellFrame.origin.x + 5;
cellFrame = newCellFrame;
if (localPoint.x <= cellFrame.origin.x + 16) {
return [super trackMouse:theEvent inRect:cellFrame ofView:controlView untilMouseUp:untilMouseUp];
} else {
return NO;
}
}
-(NSRect)drawTitle:(NSAttributedString *)title withFrame:(NSRect)frame inView:(NSView *)controlView {
// Adjust the rect so we don't interfere with the image's location
if (image != nil) {
//NSLog(#"orig %f %f %f %f", frame.size.width,frame.size.height,frame.origin.x,frame.origin.y);
NSRect newFrame = NSOffsetRect(frame, [[self image] size].width + KNImageAndTextButtonCellPadding, 0);
newFrame.size.width -= ([[self image] size].width + KNImageAndTextButtonCellPadding);
//NSLog(#"drawTitle %f %f %f %f", newFrame.size.width,newFrame.size.height,newFrame.origin.x,newFrame.origin.y);
return [super drawTitle:title withFrame:newFrame inView:controlView];
} else {
return [super drawTitle:title withFrame:frame inView:controlView];
}
}
- (void)editWithFrame:(NSRect)aRect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)anObject event:(NSEvent *)theEvent {
NSLog(#"%#", anObject);
// id node = [anObject itemAtRow: [anObject selectedRow]];
// int length = [[node relativePath] length];
NSRect newFrame = NSOffsetRect(aRect, KNImageAndTextButtonCellPadding+kIconImageSize+ 16, 0);
newFrame.size.width -= (KNImageAndTextButtonCellPadding+kIconImageSize+ 16);
[super editWithFrame:newFrame inView:controlView editor:textObj delegate:anObject event:theEvent];
}
I am getting always 1 (boolean value) in
- (void)outlineView:(NSOutlineView *)ov
setObjectValue:(id)obj
forTableColumn:(NSTableColumn *)tableColumn
byItem:(id)item
NSOutlineView delegate method.(because of NSButtonCell) but i want to edit label.
How can i edit label?
How to handle double click ?
Before pressing enter key:
After
How to change color text? its displaying white color.
it should be like (with checkbox)
Can anyone please help me out?