UiButton action method not working - ios7

I have a banner view that comes over navigation. I have added a custom button that i have added like:
- (id) initWithNotification:(JCNotificationBanner*)notification {
self = [super init];
if (self) {
isPresentedMutex = [NSObject new];
self.backgroundColor = [UIColor clearColor];
self.iconImageView = [UIImageView new];
self.iconImageView.image = [UIImage imageNamed:#"close.png"];
[self addSubview:self.iconImageView];
self.titleLabel = [UILabel new];
self.titleLabel.font = [UIFont boldSystemFontOfSize:16];
self.titleLabel.textColor = [UIColor lightTextColor];
self.titleLabel.backgroundColor = [UIColor clearColor];
[self addSubview:self.titleLabel];
self.messageLabel = [UILabel new];
self.messageLabel.font = [UIFont systemFontOfSize:14];
self.messageLabel.textColor = [UIColor lightTextColor];
self.messageLabel.backgroundColor = [UIColor clearColor];
self.messageLabel.numberOfLines = 0;
[self addSubview:self.messageLabel];
// Button
_detailDisclosureButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_detailDisclosureButton setBackgroundImage:[UIImage imageNamed:#"disclosure.png"] forState:UIControlStateNormal];
[_detailDisclosureButton setBackgroundImage:nil forState:UIControlStateSelected];
// _detailDisclosureButton.hidden = NO;
[_detailDisclosureButton addTarget:self action:#selector(detailDisclosureButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[_detailDisclosureButton setEnabled:YES];
[self addSubview:_detailDisclosureButton];
UITapGestureRecognizer* tapRecognizer;
tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
action:#selector(handleSingleTap:)];
[self addGestureRecognizer:tapRecognizer];
self.notificationBanner = notification;
}
return self;
}
Here is what my draw context method is calling.
- (void) drawRect:(CGRect)rect {
CGRect bounds = self.bounds;
CGFloat lineWidth = kJCNotificationBannerViewOutlineWidth;
CGFloat radius = 10;
CGFloat height = bounds.size.height;
CGFloat width = bounds.size.width;
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetAllowsAntialiasing(context, true);
CGContextSetShouldAntialias(context, true);
CGMutablePathRef outlinePath = CGPathCreateMutable();
CGPathMoveToPoint(outlinePath, NULL, lineWidth, 0);
CGPathAddLineToPoint(outlinePath, NULL, lineWidth, height - radius - lineWidth);
CGPathAddArc(outlinePath, NULL, radius + lineWidth, height - radius - lineWidth, radius, -M_PI, M_PI_2, 1);
CGPathAddLineToPoint(outlinePath, NULL, width - radius - lineWidth, height - lineWidth);
CGPathAddArc(outlinePath, NULL, width - radius - lineWidth, height - radius - lineWidth, radius, M_PI_2, 0, 1);
CGPathAddLineToPoint(outlinePath, NULL, width - lineWidth, 0);
CGContextSetRGBFillColor(context, 0, 0, 0, 0.9);
CGContextAddPath(context, outlinePath);
CGContextFillPath(context);
CGContextAddPath(context, outlinePath);
CGContextSetRGBFillColor(context, 0, 0, 0, 1);
CGContextSetLineWidth(context, lineWidth);
CGContextDrawPath(context, kCGPathStroke);
CGPathRelease(outlinePath);
}
And my layout subview methods that arrange frame are like:
- (void) layoutSubviews {
if (!(self.frame.size.width > 0)) { return; }
BOOL hasTitle = notificationBanner ? (notificationBanner.title.length > 0) : NO;
CGFloat borderY = kJCNotificationBannerViewOutlineWidth + kJCNotificationBannerViewMarginY;
CGFloat borderX = kJCNotificationBannerViewOutlineWidth + kJCNotificationBannerViewMarginX;
CGFloat currentX = borderX;
CGFloat currentY = borderY;
CGFloat contentWidth = self.frame.size.width - (borderX * 2.0);
currentY += 2.0;
if (hasTitle) {
self.titleLabel.frame = CGRectMake(currentX, currentY, contentWidth, 22.0);
currentY += 22.0;
}
self.messageLabel.frame = CGRectMake(currentX, currentY, contentWidth, (self.frame.size.height - borderY) - currentY);
[self.messageLabel sizeToFit];
CGRect messageFrame = self.messageLabel.frame;
CGFloat spillY = (currentY + messageFrame.size.height + kJCNotificationBannerViewMarginY) - self.frame.size.height;
if (spillY > 0.0) {
messageFrame.size.height -= spillY;
self.messageLabel.frame = messageFrame;
}
_detailDisclosureButton.frame = CGRectMake(285,self.center.y-15,29,29);
}
My Button action method named detailDisclosureButtonPressed is not being called. Please help me out in this ?

Related

How to remove already created path using CGMutablePathRef?

I am plotting line according bottom selected dots.First Showing start from 0 and after that it showing according to selected dots But line chart is showing previous drawn line.
Here I am using SHLineGrapgView. Here is code :
- (void)drawPlot:(SHPlot *)plot {
NSDictionary *theme = plot.plotThemeAttributes;
//
CAShapeLayer *backgroundLayer = [CAShapeLayer layer];
backgroundLayer.frame = self.bounds;
backgroundLayer.fillColor = [UIColor clearColor].CGColor;
backgroundLayer.backgroundColor = [UIColor clearColor].CGColor;
[backgroundLayer setStrokeColor:[UIColor clearColor].CGColor];
[backgroundLayer setLineWidth:((NSNumber *)theme[kPlotStrokeWidthKey]).intValue];
CGMutablePathRef backgroundPath= CGPathCreateMutable();
//
CAShapeLayer *circleLayer = [CAShapeLayer layer];
circleLayer.frame = self.bounds;
circleLayer.fillColor = [UIColor redColor].CGColor;
circleLayer.backgroundColor = [UIColor clearColor].CGColor;
[circleLayer setStrokeColor:((UIColor *)theme[kPlotPointFillColorKey]).CGColor];
[circleLayer setLineWidth:((NSNumber *)theme[kPlotStrokeWidthKey]).intValue];
CGMutablePathRef circlePath = CGPathCreateMutable();
//
CAShapeLayer *graphLayer = [CAShapeLayer layer];
graphLayer.frame = self.bounds;
graphLayer.fillColor = [UIColor clearColor].CGColor;
graphLayer.backgroundColor = [UIColor clearColor].CGColor;
[graphLayer setStrokeColor:((UIColor *)theme[kPlotStrokeColorKey]).CGColor];
[graphLayer setLineWidth:((NSNumber *)theme[kPlotStrokeWidthKey]).intValue];
CGMutablePathRef graphPath = CGPathCreateMutable();
double yRange = [_yAxisRange doubleValue]; // this value will be in dollars
double yIntervalValue = yRange / INTERVAL_COUNT;
//logic to fill the graph path, ciricle path, background path.
NSLog(#"plottingValues Dictionary %#",plot.plottingValues);
[plot.plottingValues enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSDictionary *dic = (NSDictionary *)obj;
NSLog(#"Plotting Dictionary %#",dic);
__block NSNumber *_key = nil;
__block NSNumber *_value = nil;
[dic enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
_key = (NSNumber *)key;
_value = (NSNumber *)obj;
}];
int xIndex = [self getIndexForValue:_key forPlot:plot];
//x value
double height = self.bounds.size.height - BOTTOM_MARGIN_TO_LEAVE;
double y = height - ((height / ([_yAxisRange doubleValue] + yIntervalValue)) * [_value doubleValue]);
(plot.xPoints[xIndex]).x = ceil((plot.xPoints[xIndex]).x);
(plot.xPoints[xIndex]).y = ceil(y);
}];
//move to initial point for path and background.
CGPathMoveToPoint(graphPath, NULL, _leftMarginToLeave, plot.xPoints[0].y);
CGPathMoveToPoint(backgroundPath, NULL, _leftMarginToLeave, plot.xPoints[0].y);
int count = (int)_xAxisValues.count;
for(int i=0; i< count; i++)
{
CGPathRef path=CGPathCreateCopy(graphPath);
CGPoint point = plot.xPoints[i];
// CGContextRef ref=CGContextCopyPath(<#CGContextRef _Nullable c#>)
// CGContextClip
CGPathAddLineToPoint(graphPath, NULL, point.x, point.y);
CGPathAddLineToPoint(backgroundPath, NULL, point.x, point.y);
CGFloat dotsSize = [_themeAttributes[kDotSizeKey] floatValue];
CGPathAddEllipseInRect(circlePath, NULL, CGRectMake(point.x - dotsSize/2.0f, point.y - dotsSize/2.0f, dotsSize, dotsSize));
}
//move to initial point for path and background.
CGPathAddLineToPoint(NULL, NULL, _leftMarginToLeave + PLOT_WIDTH, plot.xPoints[count -1].y);
CGPathAddLineToPoint(backgroundPath, NULL, _leftMarginToLeave + PLOT_WIDTH, plot.xPoints[count - 1].y);
//additional points for background.
CGPathAddLineToPoint(backgroundPath, NULL, _leftMarginToLeave + PLOT_WIDTH, self.bounds.size.height - BOTTOM_MARGIN_TO_LEAVE);
CGPathAddLineToPoint(backgroundPath, NULL, _leftMarginToLeave, self.bounds.size.height - BOTTOM_MARGIN_TO_LEAVE);
CGPathCloseSubpath(backgroundPath);
backgroundLayer.path = backgroundPath;
graphLayer.path = graphPath;
circleLayer.path = circlePath;
//animation
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:#"strokeEnd"];
animation.duration = 1;
animation.fromValue = #(0.0);
animation.toValue = #(1.0);
[graphLayer addAnimation:animation forKey:#"strokeEnd"];
backgroundLayer.zPosition = 0;
graphLayer.zPosition = 1;
circleLayer.zPosition = 2;
[self.layer addSublayer:graphLayer];
[self.layer addSublayer:circleLayer];
[self.layer addSublayer:backgroundLayer];
NSUInteger count2 = _xAxisValues.count;
for(int i=0; i< count2; i++){
CGPoint point = plot.xPoints[i];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.backgroundColor = [UIColor clearColor];
btn.tag = i;
btn.frame = CGRectMake(point.x, point.y - 20, 40, 40);
[btn addTarget:self action:#selector(clicked:) forControlEvents:UIControlEventTouchUpInside];
objc_setAssociatedObject(btn, kAssociatedPlotObject, plot, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[self addSubview:btn];
}
}

Objective-C Moving object along curved path

I've looked at other SO answers to this quesiton, particularly Brad Larson's but I am still not getting any results. I'm not sure if I am approaching this the correct way. In my app, when a user touches the screen I capture the point and create an arc from a fixed point to that touch point. I then want to move a UIView along that arc.
Here's my code:
ViewController.m
//method to "shoot" object - KIP_Projectile creates the arc, KIP_Character creates the object I want to move along the arc
...
//get arc for trajectory
KIP_Projectile* vThisProjectile = [[KIP_Projectile alloc] initWithFrame:CGRectMake(51.0, fatElvisCenterPoint-30.0, touchPoint.x, 60.0)];
vThisProjectile.backgroundColor = [UIColor clearColor];
[self.view addSubview:vThisProjectile];
...
KIP_Character* thisChar = [[KIP_Character alloc] initWithFrame:CGRectMake(51, objCenterPoint-5, imgThisChar.size.width, imgThisChar.size.height)];
thisChar.backgroundColor = [UIColor clearColor];
thisChar.charID = charID;
thisChar.charType = 2;
thisChar.strCharType = #"Projectile";
thisChar.imgMyImage = imgThisChar;
thisChar.myArc = vThisProjectile;
[thisChar buildImage];
[thisChar traceArc];
in KIP_Projectile I build the arc using this code:
- (CGMutablePathRef) createArcPathFromBottomOfRect : (CGRect) rect : (CGFloat) arcHeight {
CGRect arcRect = CGRectMake(rect.origin.x, rect.origin.y + rect.size.height - arcHeight, rect.size.width, arcHeight);
CGFloat arcRadius = (arcRect.size.height/2) + (pow(arcRect.size.width, 2) / (8*arcRect.size.height));
CGPoint arcCenter = CGPointMake(arcRect.origin.x + arcRect.size.width/2, arcRect.origin.y + arcRadius);
CGFloat angle = acos(arcRect.size.width / (2*arcRadius));
CGFloat startAngle = radians(180) + angle;
CGFloat endAngle = radians(360) - angle;
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddArc(path, NULL, arcCenter.x, arcCenter.y, arcRadius, startAngle, endAngle, 0);
return path;
}
- (void)drawRect:(CGRect)rect {
CGContextRef currentContext = UIGraphicsGetCurrentContext();
_myArcPath = [self createArcPathFromBottomOfRect:self.bounds:30.0];
CGContextSetLineWidth(currentContext, 1);
CGFloat red[4] = {1.0f, 0.0f, 0.0f, 1.0f};
CGContextSetStrokeColor(currentContext, red);
CGContextAddPath(currentContext, _myArcPath);
CGContextStrokePath(currentContext);
}
Works fine. The arc is displayed with a red stroke on the screen.
In KIP_Character, which has been passed it's relevant arc, I am using this code but getting no results.
- (void) traceArc {
CGMutablePathRef myArc = _myArc.myArcPath;
// Set up path movement
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:#"position"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
pathAnimation.path = myArc;
CGPathRelease(myArc);
[self.layer addAnimation:pathAnimation forKey:#"savingAnimation"];
}
Any help here would be appreciated.

UIScrollView and UIPageControl, what am I doing wrong?

I have a class which is predefining some labels and binding their values in a UIScrollView.
I've managed to show those labels, but now I'm stuck at putting a label at the 2nd part of the ScrollView.
I've pushed my project to gitHub.
I can change the label's place on the already visible part, but I must be overlooking something.
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.title = _detail.name;
UIColor *bgColor = [UIColor blackColor];
UIColor *txtColor = [UIColor grayColor];
CGRect frame;
frame.origin.x = 0;
frame.origin.y = 0;
frame.size.width = _scrollView.frame.size.width *2;
NSString *phoneNr = (_detail.phoneNr == nil) ? #"Not specified" : _detail.phoneNr;
_telLabel = [self prepareLabel:phoneNr textColor:txtColor bgColor:bgColor page:0 y:telNrYAxis];
_webLabel = [self prepareLabel:#"Visit website" textColor:txtColor bgColor:bgColor page:0 y:websiteYAxis];
_detail.address = [_detail.address stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#"\n\t "]];
NSArray *addressArrComponents = [_detail.address componentsSeparatedByString:#","] ;
_addressLabel = [self prepareLabel:[addressArrComponents componentsJoinedByString:#"\n"] textColor:txtColor bgColor:bgColor page:0 y:addressYAxis];
UILabel *lbl = [self prepareLabel:#"Derp" textColor:txtColor bgColor:bgColor page:1 y:0];
_detailView = [[UIView alloc] initWithFrame:frame];
_detailView.backgroundColor = [UIColor blackColor];
[_detailView addSubview:_webLabel];
[_detailView addSubview:_addressLabel];
[_detailView addSubview:_telLabel];
[_detailView addSubview:lbl];
[_scrollView addSubview:_detailView];
NSLog(#"%f",self.view.frame.size.height - (_scrollView.frame.origin.y + _scrollView.frame.size.height) );
_pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height - 250 , self.view.frame.size.width/4, 120)];
_pageControl.numberOfPages=2;
_pageControl.currentPage=0;
[_pageControl addTarget:self action:#selector(pageChange:) forControlEvents:UIControlEventTouchDown];
_scrollView.contentSize = CGSizeMake(800,800);
_scrollView.delegate=self;
_scrollView.backgroundColor = [UIColor blackColor];
_scrollView.pagingEnabled=YES;
_scrollView.showsHorizontalScrollIndicator = NO;
_scrollView.showsVerticalScrollIndicator = NO;
_scrollView.scrollsToTop = NO;
[self pageChange:0];
[self.view addSubview:_pageControl];
// Do any additional setup after loading the view.
}
-(UILabel*)prepareLabel:(NSString*) text textColor:(UIColor*)textColor bgColor:(UIColor*)backgroundColor page:(int)page y:(int) yPos{
int lines = [[text componentsSeparatedByString:#"\n"] count];
CGRect labelFrame = CGRectMake(_detailView.frame.size.width * page +20,yPos,self.view.frame.size.width, [UIFont systemFontSize]*lines);
UILabel *returnLabel = [[UILabel alloc] initWithFrame:labelFrame];
returnLabel.text = text;
returnLabel.backgroundColor = backgroundColor;
returnLabel.textColor = textColor;
[returnLabel setNumberOfLines:lines];
[returnLabel sizeToFit];
return returnLabel;
}
- (void)loadScrollViewWithPage:(int)page {
NSLog(#"Derped");
}
-(IBAction)pageChange:(id)sender{
int page=_pageControl.currentPage;
CGRect frame = _scrollView.frame;
frame.origin.x = _scrollView.frame.size.width * page;
frame.origin.y = 0;
//CGRect frame= (page == 0) ? _detailFrame : _reviewFrame;
NSLog(#"%f",frame.origin.x);
[_scrollView scrollRectToVisible:frame animated:YES];
}
The delegate -(IBAction)pageChange:(id)sender gets fired, but I must be doing something wrong with the frames somewhere :s
Please take a look!
Try to implement this method may help you :
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat pageWidth = self.scrollView.frame.size.width;
float fractionalPage = self.scrollView.contentOffset.x / pageWidth;
NSInteger page = lround(fractionalPage);
self.pageControl.currentPage = page;
}

ios Help Screen semi-transparent overlay

Wondering if anyone can shed some light on how to create a semi-transparent Help screen on an ipad or iphone app? Something similar to Googles app.
I have a splitViewController and I want to overlay a see-through black overlay on top of the splitViewController where I can show Help information about each item you can click in the splitViewController.
I followed http://cocoawithlove.com/2009/04/showing-message-over-iphone-keyboard.html which gets me the overlay, but I am now adding clickable UIViews (eg a close button to dismiss the overlay). The issue is when I setup touchesEnded:withEvent I cannot seem to convert clicks from the main LoadingView to closeButton to see what was actually clicked?
See the touches ended at the end of the code
================================================================
#import "HelpView.h"
#import <QuartzCore/QuartzCore.h>
//
CGPathRef NewPathWithRoundRect(CGRect rect, CGFloat cornerRadius)
{
//
// Create the boundary path
//
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL,
rect.origin.x,
rect.origin.y + rect.size.height - cornerRadius);
// Top left corner
CGPathAddArcToPoint(path, NULL,
rect.origin.x,
rect.origin.y,
rect.origin.x + rect.size.width,
rect.origin.y,
cornerRadius);
// Top right corner
CGPathAddArcToPoint(path, NULL,
rect.origin.x + rect.size.width,
rect.origin.y,
rect.origin.x + rect.size.width,
rect.origin.y + rect.size.height,
cornerRadius);
// Bottom right corner
CGPathAddArcToPoint(path, NULL,
rect.origin.x + rect.size.width,
rect.origin.y + rect.size.height,
rect.origin.x,
rect.origin.y + rect.size.height,
cornerRadius);
// Bottom left corner
CGPathAddArcToPoint(path, NULL,
rect.origin.x,
rect.origin.y + rect.size.height,
rect.origin.x,
rect.origin.y,
cornerRadius);
// Close the path at the rounded rect
CGPathCloseSubpath(path);
return path;
}
#implementation HelpView
#synthesize closeButton = _closeButton;
- (id)loadingViewInView:(UIView *)aSuperview
{
HelpView *loadingView =
[[HelpView alloc] initWithFrame:[aSuperview bounds]];
if (!loadingView)
{
return nil;
}
loadingView.opaque = NO;
loadingView.autoresizingMask =
UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[aSuperview addSubview:loadingView];
const CGFloat DEFAULT_LABEL_WIDTH = 100.0;
const CGFloat DEFAULT_LABEL_HEIGHT = 40.0;
CGRect labelFrame = CGRectMake(0, 0, DEFAULT_LABEL_WIDTH, DEFAULT_LABEL_HEIGHT);
UILabel *loadingLabel = [[UILabel alloc] initWithFrame:labelFrame];
loadingLabel.text = NSLocalizedString(#"Close", nil);
loadingLabel.textColor = [UIColor whiteColor];
loadingLabel.backgroundColor = [UIColor clearColor];
loadingLabel.textAlignment = UITextAlignmentCenter;
loadingLabel.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]];
loadingLabel.autoresizingMask =
UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin;
// Background for Close button
CALayer *closeButtonBackground = [CALayer layer];
closeButtonBackground.opacity = 0.3;
closeButtonBackground.borderColor = [UIColor whiteColor].CGColor;
closeButtonBackground.borderWidth = 2.0;
closeButtonBackground.cornerRadius = 5.0;
closeButtonBackground.backgroundColor = [UIColor blackColor].CGColor;
// Finish setting up frame for Close button
labelFrame.origin.x = 0;
labelFrame.origin.y = 0;
loadingLabel.frame = labelFrame;
closeButtonBackground.frame = labelFrame;
CGRect viewRect = CGRectMake(loadingView.frame.size.width -150 ,loadingView.frame.size.height - 85,100,40);
self.closeButton = [[UIView alloc] initWithFrame:viewRect];
self.closeButton.userInteractionEnabled = YES;
self.userInteractionEnabled = NO;
[loadingView addSubview:self.closeButton];
[self.closeButton.layer addSublayer:closeButtonBackground];
[self.closeButton addSubview:loadingLabel];
// Set up the fade-in animation
CATransition *animation = [CATransition animation];
[animation setType:kCATransitionFade];
[[aSuperview layer] addAnimation:animation forKey:#"layerAnimation"];
//[loadingView createGestureRecognizer];
return loadingView;
}
- (void)removeView
{
UIView *aSuperview = [self superview];
[super removeFromSuperview];
// Set up the animation
CATransition *animation = [CATransition animation];
[animation setType:kCATransitionFade];
[[aSuperview layer] addAnimation:animation forKey:#"layerAnimation"];
}
- (void)drawRect:(CGRect)rect
{
rect.size.height -= 1;
rect.size.width -= 1;
const CGFloat RECT_PADDING = 0.0;
rect = CGRectInset(rect, RECT_PADDING, RECT_PADDING);
const CGFloat ROUND_RECT_CORNER_RADIUS = 0.0;
CGPathRef roundRectPath = NewPathWithRoundRect(rect, ROUND_RECT_CORNER_RADIUS);
CGContextRef context = UIGraphicsGetCurrentContext();
const CGFloat BACKGROUND_OPACITY = 0.85;
CGContextSetRGBFillColor(context, 0, 0, 0, BACKGROUND_OPACITY);
CGContextAddPath(context, roundRectPath);
CGContextFillPath(context);
const CGFloat STROKE_OPACITY = 0.25;
CGContextSetRGBStrokeColor(context, 1, 1, 1, STROKE_OPACITY);
CGContextAddPath(context, roundRectPath);
CGContextStrokePath(context);
CGPathRelease(roundRectPath);
}
- (void)handleSingleDoubleTap:(UITapGestureRecognizer *)sender {
NSLog(#"");
CGPoint tapPoint = [sender locationInView:sender.view];
CALayer* layerThatWasTapped = [self.layer hitTest:tapPoint];
CGPoint convertedPoint = [layerThatWasTapped convertPoint:layerThatWasTapped.position toLayer:self.closeButton.layer];
BOOL myBool = [self.closeButton.layer containsPoint:convertedPoint];
[UIView beginAnimations:nil context:NULL];
sender.view.center = tapPoint;
[UIView commitAnimations];
}
- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event {
UITouch *touch = [touches anyObject];
CGPoint point = [touch locationInView: self];
CGPoint convertedPoint = [self convertPoint:point toView:[self.closeButton superview]];
if (CGRectContainsPoint(self.closeButton.bounds, convertedPoint)) {
NSLog (#"YAY!");
}
} // touchesEnded
Solved this with NSNotifications. Something like this... its a little static... should be more dynamic.
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(eventHandler:)
name:#"SomeButtonClicked"
object:nil ];
-(void)eventHandler: (NSNotification *) notification
{
NSString *buttonWhichWasClicked = [[notification userInfo] objectForKey:#"buttonName"];
NSLog(#" %#", buttonWhichWasClicked);
if ([buttonWhichWasClicked isEqualToString:#"close"]){
[self removeView];
}
//Tell other buttons to dim/remove themselves as a new one was selected
}
- (void)removeView
{
//code to remove view
}

drawWithFrame NSOutlineView Flickr

I have a custom cell class for NSOutlineView
In the cell class I have implemented the drawWithFrame.
The rect provided(cellFrame) I divide into 3 parts
(a) Image
(b) Text
(c) Darwing (ellipse/circle / rectangle)
The image is drawn using [image compositeToPoint:imageFrame.origin operation:NSCompositeSourceOver];
The ellipse is drawn using [[NSBezierPath bezierPathWithRoundedRect:ellipseRect xRadius:10 yRadius:10] fill];
The text rect is given to the super class to draw the text
[super drawInteriorWithFrame:newFrame inView:controlView];
Now my problem is that when any cell of the outline view expands, all the drawing (ellipse etc) flickr and appear to be redrawn, even if the cell was not expanded.
Can anyone help me to resolve this..
Here is the code
- (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView*)controlView
{
//cellFrame.size.height -=16;
Option *ol = [self representedObject];
uint64_t sz;
int fontSize=10;
NSString *sizeText;
MyFile *tmpf;
//NSImage *image = [ol getImage];
if (image != nil)
{
// the cell has an image: draw the normal item cell
NSSize imageSize;
NSRect imageFrame;
imageSize = [image size];
NSDivideRect(cellFrame, &imageFrame, &cellFrame, 3 + imageSize.width, NSMinXEdge);
imageFrame.origin.x += kImageOriginXOffset;
imageFrame.origin.y -= kImageOriginYOffset;
imageFrame.size = NSMakeSize(12,12);
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);
[image compositeToPoint:imageFrame.origin operation:NSCompositeSourceOver];
imageFrame.origin.y+=18;
imageFrame.size.width = cellFrame.size.width - 18;
imageFrame.origin.x+=18;
sz = [ol getsize];
/////////////////////////////////
NSRect newFrame = cellFrame;
newFrame.origin.x += kTextOriginXOffset;
newFrame.origin.y += kTextOriginYOffset;
newFrame.size.height -= kTextHeightAdjust;
newFrame.size.width -= 65;
if(sz)
{
//newFrame.origin.x += 65;
NSRect tmpframe = newFrame;
NSRect ellipseRect = NSMakeRect(tmpframe.origin.x+tmpframe.size.width+1,
tmpframe.origin.y+ kTextOriginYOffset,
60,16);
//////// ****ALLOC ********
tmpf = [[MyFile alloc] init];
[tmpf setfsize:sz];
sizeText = [tmpf getFormattedfize];
// [NSShadow setShadowWithOffset:NSMakeSize(0, -8 * 1) blurRadius:12 * 1
// color:[NSColor colorWithCalibratedWhite:0 alpha:0.75]];
[[NSColor colorWithCalibratedWhite:0.9 alpha:1.0] set];
[[NSBezierPath bezierPathWithRoundedRect:ellipseRect xRadius:10 yRadius:10] fill];
// [NSShadow clearShadow];
TextAttributes = [NSDictionary dictionaryWithObjectsAndKeys: [NSColor textColor],
NSForegroundColorAttributeName,
[NSFont systemFontOfSize:10],
NSFontAttributeName, nil];
[sizeText drawAtPoint:NSMakePoint(ellipseRect.origin.x+3, ellipseRect.origin.y+2)
withAttributes:TextAttributes];
//////// ****RELEASE *******
[tmpf release];
}
[super drawInteriorWithFrame:newFrame inView:controlView];
}
}