Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PopTip without pointing somewhere #55

Open
SjoerdPerfors opened this issue Nov 22, 2013 · 2 comments
Open

PopTip without pointing somewhere #55

SjoerdPerfors opened this issue Nov 22, 2013 · 2 comments

Comments

@SjoerdPerfors
Copy link

This can come handy when you want to show a poptip to a mkmapview or a global one for a screen. So my goal was to get a poptip without the arrow.

To archive this I added to the enum:

typedef enum {
    PointDirectionAny = 0,
    PointDirectionUp,
    PointDirectionDown,
    PointDirectionGoneButDown,
    PointDirectionGoneButUp
} PointDirection;

Then in - (void)drawRect:(CGRect)rect {

for example the PointDirectionDown:

else {
    if(_pointDirection == PointDirectionGoneButDown)
        CGPathMoveToPoint(bubblePath, NULL, _targetPoint.x+_sidePadding, _targetPoint.y - _pointerSize);
    else
        CGPathMoveToPoint(bubblePath, NULL, _targetPoint.x+_sidePadding, _targetPoint.y);
@rpungin
Copy link

rpungin commented Apr 1, 2014

Hi SjoerdPerfors.

I can't get it to work with the code you provided. Can you please provide the complete code that handles not having the pointers?

Thanks!
Raphael

@SjoerdPerfors
Copy link
Author

Sorry Raphael, I forgot the following.

Change in method

  • (void)presentPointingAtView:(UIView *)targetView inView:(UIView *)containerView animated:(BOOL)animated

the following: if (_pointDirection == PointDirectionDown || _pointDirection == PointDirectionGoneButDown) see snipper below

if (targetRelativeOrigin.y+targetView.bounds.size.height < containerRelativeOrigin.y) {
    pointerY = 0.0;
    _pointDirection = PointDirectionUp;
}
else if (targetRelativeOrigin.y > containerRelativeOrigin.y+containerView.bounds.size.height) {
    pointerY = containerView.bounds.size.height;
    _pointDirection = PointDirectionDown;
}
else {
    _pointDirection = _preferredPointDirection;
    CGPoint targetOriginInContainer = [targetView convertPoint:CGPointMake(0.0, 0.0) toView:containerView];
    CGFloat sizeBelow = containerView.bounds.size.height - targetOriginInContainer.y;
    if (_pointDirection == PointDirectionAny) {
        if (sizeBelow > targetOriginInContainer.y) {
            pointerY = targetOriginInContainer.y + targetView.bounds.size.height;
            _pointDirection = PointDirectionUp;
        }
        else {
            pointerY = targetOriginInContainer.y;
            _pointDirection = PointDirectionDown;
        }
    }
    else {
        if (_pointDirection == PointDirectionDown || _pointDirection == PointDirectionGoneButDown) {
            pointerY = targetOriginInContainer.y;
        }
        else {
            pointerY = targetOriginInContainer.y + targetView.bounds.size.height;
        }
    }
}

My top lines of the drawRect method looks like this (I didnt implement the PointDirectionGoneButUp):

- (void)drawRect:(CGRect)rect {

    CGRect bubbleRect = [self bubbleFrame];

    CGContextRef c = UIGraphicsGetCurrentContext(); 

    CGContextSetRGBStrokeColor(c, 0.0, 0.0, 0.0, 1.0);  // black
    CGContextSetLineWidth(c, self.borderWidth);

    CGMutablePathRef bubblePath = CGPathCreateMutable();

    if (_pointDirection == PointDirectionUp) {
        CGPathMoveToPoint(bubblePath, NULL, _targetPoint.x+_sidePadding, _targetPoint.y);
        CGPathAddLineToPoint(bubblePath, NULL, _targetPoint.x+_sidePadding+_pointerSize, _targetPoint.y+_pointerSize);

        CGPathAddArcToPoint(bubblePath, NULL,
                            bubbleRect.origin.x+bubbleRect.size.width, bubbleRect.origin.y,
                            bubbleRect.origin.x+bubbleRect.size.width, bubbleRect.origin.y+_cornerRadius,
                            _cornerRadius);
        CGPathAddArcToPoint(bubblePath, NULL,
                            bubbleRect.origin.x+bubbleRect.size.width, bubbleRect.origin.y+bubbleRect.size.height,
                            bubbleRect.origin.x+bubbleRect.size.width-_cornerRadius, bubbleRect.origin.y+bubbleRect.size.height,
                            _cornerRadius);
        CGPathAddArcToPoint(bubblePath, NULL,
                            bubbleRect.origin.x, bubbleRect.origin.y+bubbleRect.size.height,
                            bubbleRect.origin.x, bubbleRect.origin.y+bubbleRect.size.height-_cornerRadius,
                            _cornerRadius);
        CGPathAddArcToPoint(bubblePath, NULL,
                            bubbleRect.origin.x, bubbleRect.origin.y,
                            bubbleRect.origin.x+_cornerRadius, bubbleRect.origin.y,
                            _cornerRadius);
        CGPathAddLineToPoint(bubblePath, NULL, _targetPoint.x+_sidePadding-_pointerSize, _targetPoint.y+_pointerSize);
    }
    else {
        if(_pointDirection == PointDirectionGoneButDown)
            CGPathMoveToPoint(bubblePath, NULL, _targetPoint.x+_sidePadding, _targetPoint.y - _pointerSize);
        else
            CGPathMoveToPoint(bubblePath, NULL, _targetPoint.x+_sidePadding, _targetPoint.y);
        CGPathAddLineToPoint(bubblePath, NULL, _targetPoint.x+_sidePadding-_pointerSize, _targetPoint.y-_pointerSize);

        CGPathAddArcToPoint(bubblePath, NULL,
                            bubbleRect.origin.x, bubbleRect.origin.y+bubbleRect.size.height,
                            bubbleRect.origin.x, bubbleRect.origin.y+bubbleRect.size.height-_cornerRadius,
                            _cornerRadius);
        CGPathAddArcToPoint(bubblePath, NULL,
                            bubbleRect.origin.x, bubbleRect.origin.y,
                            bubbleRect.origin.x+_cornerRadius, bubbleRect.origin.y,
                            _cornerRadius);
        CGPathAddArcToPoint(bubblePath, NULL,
                            bubbleRect.origin.x+bubbleRect.size.width, bubbleRect.origin.y,
                            bubbleRect.origin.x+bubbleRect.size.width, bubbleRect.origin.y+_cornerRadius,
                            _cornerRadius);
        CGPathAddArcToPoint(bubblePath, NULL,
                            bubbleRect.origin.x+bubbleRect.size.width, bubbleRect.origin.y+bubbleRect.size.height,
                            bubbleRect.origin.x+bubbleRect.size.width-_cornerRadius, bubbleRect.origin.y+bubbleRect.size.height,
                            _cornerRadius);
        CGPathAddLineToPoint(bubblePath, NULL, _targetPoint.x+_sidePadding+_pointerSize, _targetPoint.y-_pointerSize);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants