Giter VIP home page Giter VIP logo

cmpoptipview's Introduction

CMPopTipView

Build Status

An iOS UIView subclass that displays a rounded rect "bubble", containing a text message, pointing at a specified button or view.

A CMPopTipView will automatically position itself within the view so that it is pointing at the specified button or view, positioning the "pointer" as necessary.

A CMPopTipView can be pointed at any UIView within the containing view. It can also be pointed at a UIBarButtonItem within either a UINavigationBar or a UIToolbar and it will automatically position itself to point at the target.

The background and text colors can be customised if the defaults are not suitable.

Two animation options are available for when a CMPopTipView is presented: "slide" and "pop".

A CMPopTipView can be dismissed by the user tapping on it. It can also be dismissed programatically.

CMPopTipView is rendered entirely by Core Graphics.

The source includes a universal (iPhone/iPad) demo app.

一个泡泡风格的提示框开源控件, 继承自UIView。iPad,iPhone通用

URLs

Used in apps:

Screenshots

Videos

http://www.youtube.com/watch?v=nul9VA_QsGI

Usage

Example 1 - point at a UIBarButtonItem in a nav bar:

// Present a CMPopTipView pointing at a UIBarButtonItem in the nav bar
CMPopTipView *navBarLeftButtonPopTipView = [[CMPopTipView alloc] initWithMessage:@"A Message"];
navBarLeftButtonPopTipView.delegate = self;
[navBarLeftButtonPopTipView presentPointingAtBarButtonItem:self.navigationItem.leftBarButtonItem animated:YES];

// Dismiss a CMPopTipView
[navBarLeftButtonPopTipView dismissAnimated:YES];

// CMPopTipViewDelegate method
- (void)popTipViewWasDismissedByUser:(CMPopTipView *)popTipView {
    // any code
}

Example 2 - pointing at a UIButton, with custom color scheme::

- (IBAction)buttonAction:(id)sender {
    // Toggle popTipView when a standard UIButton is pressed
    if (nil == self.roundRectButtonPopTipView) {
        self.roundRectButtonPopTipView = [[CMPopTipView alloc] initWithMessage:@"My message"];
        self.roundRectButtonPopTipView.delegate = self;
        self.roundRectButtonPopTipView.backgroundColor = [UIColor lightGrayColor];
        self.roundRectButtonPopTipView.textColor = [UIColor darkTextColor];

        UIButton *button = (UIButton *)sender;
        [self.roundRectButtonPopTipView presentPointingAtView:button inView:self.view animated:YES];
    }
    else {
        // Dismiss
        [self.roundRectButtonPopTipView dismissAnimated:YES];
        self.roundRectButtonPopTipView = nil;
    }
}

#pragma mark CMPopTipViewDelegate methods
- (void)popTipViewWasDismissedByUser:(CMPopTipView *)popTipView {
    // User can tap CMPopTipView to dismiss it
    self.roundRectButtonPopTipView = nil;
}

Available Options

  • id < CMPopTipViewDelegate > delegate
  • UIColor *backgroundColor
  • BOOL disableTapToDismiss
  • BOOL dismissTapAnywhere
  • NSString *title
  • NSString *message
  • UIView *customView
  • id targetObject
  • UIColor *titleColor
  • UIFont *titleFont
  • UIColor *textColor
  • UIFont *textFont
  • NSTextAlignment titleAlignment
  • NSTextAlignment textAlignment
  • BOOL has3DStyle
  • UIColor *borderColor
  • CGFloat cornerRadius
  • CGFloat borderWidth
  • BOOL hasShadow
  • CMPopTipAnimation animation
  • CGFloat maxWidth
  • PointDirection preferredPointDirection
  • BOOL hasGradientBackground
  • BOOL showFromCenter
  • CGFloat sidePadding
  • CGFloat topMargin
  • CGFloat pointerSize
  • CGFloat bubblePaddingX
  • CGFloat bubblePaddingY
  • BOOL dismissAlongWithUserInteraction

ARC

The CMPopTipView Master branch uses ARC as of version 2.0.

If you want a non-ARC version you should look at tag 1.3.0.

Support

CMPopTipView is provided open source with no warranty and no guarantee of support. However, best effort is made to address issues raised on Github https://github.com/chrismiles/CMPopTipView/issues .

If you would like assistance with integrating CMPopTipView or modifying it for your needs, contact the author Chris Miles [email protected] for consulting opportunities.

License

CMPopTipView is Copyright (c) 2010-2015 Chris Miles and released open source under a MIT license:

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

cmpoptipview's People

Contributors

abeltramo avatar anton-plebanovich avatar antz-nz avatar bok- avatar brycebostwick avatar chrismiles avatar coeur avatar coneybeare avatar eytanbiala avatar funnel20 avatar iamnanyi avatar ikhsan avatar jaybowang avatar jianfeng avatar jweyrich avatar kleinlieu avatar lukaszgrela avatar markrickert avatar martinjbaker avatar minimaluminium avatar mirekp avatar mjbeauregard avatar mvitolo avatar myell0w avatar parallaxe avatar shukuyen avatar srandazzo avatar stephenwakely avatar x2on avatar yichizhang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cmpoptipview's Issues

Issues when pointing to a subview in a UITableViewCell

When pointing a poptip view to a subview (say, a UIButton) in a UITableViewCell, the "inView" parameter has to be the cell in order to have the poptip view positions correctly. However, that presents a couple of issues:

  1. dismissTapAnywhere no longer works (well, maybe it does, but not as I would expect...), as the tap has to be within the cell. I resolve this by including an invisible button covering the whole screen.
  2. the table section title and cell borders are now on top of the poptip view. I am not sure how to resolve this issue.

Could you please provide a fix or a workaround?

Cheers,
William

Reset autoDismissTimer in autoDismissAnimated:atInterval:

Only first entry is used e.g. when I want to reset default setup I can't as the timer is already set:

[popTipView autoDismissAnimated:YES at Interval:1.0];//used
[popTipView autoDismissAnimated:YES at Interval:10.0];//ignored

in real life it would be something along:

CMPopTipView *default = [self tooltipWithMessage:@"Message"];//default used
[default autoDismissAnimated:YES at Interval:10.0];//ignored

This can be fixed by adding:

[self.autoDismissTimer invalidate]; self.autoDismissTimer = nil;

in autoDismissAnimated:atInterval: before setting new timer

Width of the popview can be larger than the frame with a long title

I have mentioned this behaviour earlier in #58, but I finally found the root cause.

I have used version 2.2.0, but unfortunately it changes the width of the popview in a negative way. Also the property maxWidth is ignored completely.

Examples:
Previous version:
1

Version 2.2.0:
2

On iPhone it's even worse:
old:
3

new:
4

ROOT CAUSE
The code assumes that the title is always a single row. Of course it might contain of so much words, that they have to be defined over multiple rows.

I have solved this by:

  1. Replacing the lineBreakMode for all title related code snippets:
titleParagraphStyle.lineBreakMode = NSLineBreakByWordWrapping;

This occurs in lines: 260, 279, 296, 313, 435 and 452.

  1. Correcting the options for the text frame:
options:NSStringDrawingUsesLineFragmentOrigin

This occurs in lines: 299 and 438.

After these changes the view is shown as expected with a multi-line title.

the poptip has an aliased border

The poptip's border doesn't have any aliasing on it because the clip that's applied for the gradient isn't removed before the border is drawn. Removing it gives the border a much smoother appearance. Thanks for the control. It's saved me a bunch of time.

attempt to insert nil object from objects[0]

In CMPopTipView.m at line 439:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(0x184a402d8 0x1966b40e4 0x18492c9c8 0x18492c7f8 0x100141624 0x100117f30 0x185934180 0x1849f812c 0x1849f7ddc 0x1849f5828 0x1849212d4 0x18e37f6fc 0x18951ef40 0x10010e6c0 0x196d5ea08)
libc++abi.dylib: terminating with uncaught exception of type NSException

Using the following code:

CMPopTipView * tipView = [[CMPopTipView alloc] initWithMessage:@"Some tip that's a bit long but not crazy long"];
tipView.title = @"Tip:";
tipView.delegate = self;
tipView.backgroundColor = [UIColor lightGrayColor];
tipView.textColor = [UIColor darkTextColor];
tipView.has3DStyle = NO;
tipView.hasGradientBackground = NO;
UITableViewCell * cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
[tipView presentPointingAtView:cell inView:self.view animated:YES];

iOS 8.4.

newbie..help getting this to work

This is excellent but i'm having trouble getting it to work.

I added CMPopTipView.h and .m to my project and then used example 2 to add tip for a command button. What else do I need to do?

I'm new to iOS programming so any help would be greatly appreciated!
Thank you very much.

Displaying at certain point and at tab bar items

It would be great if there was support for showing the popup at certain points (with direction) and at tab bar items.

Its a pretty good library, but this will make it the best for showing users how to use a new app.

2 compiler warnings 'Value conversion issue'

Xcode 5 shows 2 compiler warnings:

CMPopTipView.m:161:29: Implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int'

CMPopTipView.m:230:35: Implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int'

To solve them I have changed the datatype "int" to "size_t" in both lines.

Pop-up appears with incorrect orientation/placement

I have what I believe to be a fairly standard setup involving a UITabBarController (with four tab bar items).

I have setup a CMPopTipView to point at the UITabBarController's tabBar, and I have my app's main UIWindow set as the containing view.

It looks fine - but when I start my app in landscape view on the iPad, the orientation/placement of the pop-up is not correct. The pop-up appears, in fact, to be in exactly the same place as you would expect it to (correctly) be if you started the app in portrait mode.

Does anyone have any ideas why this might be the case? Is it something I am doing wrong, or is perhaps a simple one- or two-line change to the CMPopTipView source required?

Word wrap not working

I am not using ARC as my app is huge and haven't figured out how to convert everything, So I am using 1.3 of CMPopTip.

The demo app works fine.

I copied sections of the demo into my app and the text does not word wrap. It seems to be 1 line short. So in other words if it needed 3 lines, it only shows 2.

Any ideas?

Radius takes over Padding

Upon adding these two parameters (just like the demo suggested):
popTipView.cornerRadius = 2.0;
popTipView.sidePadding = 30.0f;

The Radius works fine, however because the radius is so low, the desired padding is ignored (or not taken into consideration properly) as there is still next to no padding. The code given should produce a padded (almost) square bubble, but it gives a non-padded square bubble instead.

Sorry if this was intentional and I've got the wrong end of the stick!

Other than this, this subclass is great - thank you very much for providing it.

Disabling gradient

Is there any easy way to disable gradient of the bubble without touching main library?

ios 8 crash on NSString drawWithRect:options:attributes:context:

I'm running the latest CMPopTipView (2.2) on iOS 8 (GM release) Simulator on OSX Yosemite with XCode 6. No matter which device I choose to simulate my app on, I crash on line 325 of CMPopTipView.m which is the invocation of NSString drawWithRect:options:attributes:context:

I'm not familiar with the pragma marks regarding deprecation, but then I certainly haven't set any flags on my app to ignore or not ignore deprecated methods. I'm only mentioning that because of the location of those relevant bits of code.

Any ideas what this might be?

image

Text alignment bug

Thanks for the nice popup control!

Around line 231, you may want to update the following:

alignment:UITextAlignmentCenter];

with

alignment:self.textAlignment];

Crash when using dismissTapAnywhere and autoDismissAnimated

Hi Chris,

When I use a tip view as such:

        CMPopTipView *tipView = [[CMPopTipView alloc] initWithMessage:@"Test message!"];
        tipView.dismissTapAnywhere = YES;
        [tipView autoDismissAnimated:YES atTimeInterval:3.0];
        [tipView presentPointingAtBarButtonItem:self.navigationItem.rightBarButtonItem animated:YES];

and tap the screen to dismiss the tip, I get a crash a few seconds later after the 3 sec timeout expires:

*** -[UIButton removeFromSuperview]: message sent to deallocated instance

It happens in finaliseDismiss when you call removeFromSuperview because self->dismissTarget has already been deallocated. Maybe a retain needed for dismissTarget?

Cheers

Update cocoa pods version

Thanks a lot for great library. I really love it:-)
Cocoa pods version is still 1.2.0
I would really appreciate if you could update cocoa pods to latest code base.

p.s.
I love "hasGradient" option.
It would be even better if you could merge "hasGradient" pull request before updating cocoa pods spec.

Handle view rotation

Would be great if the pop tip would respond to willAnimateRotationToInterfaceOrientation itself, and adjust it's position accordingly.

Means that it will also probably have to keep track of it's attachment view and visibility flag.

Ensure tip is on top of other views

Sometimes the tipView is hidden below another view when pointing to a bar button item on a toolbar. Adding the following as the final line in presentPointingAtView:inView:animated: ensures the tip is on the top:

self.layer.zPosition = MAXFLOAT;

Can't clone

Can't seem to be able to clone the project at all. Possibly a symlink issue in the latest commit?

All I get is: "Sorry, this tree took too long to generate."

This happens on both the web UI and when trying to clone it.

Popup always shown in portrait regardless of rotation in some cases.

In presentPointingAtBarButtonItem:
...
if ([targetSuperview isKindOfClass:[UINavigationBar class]]) {
containerView = [UIApplication sharedApplication].keyWindow;
}

This sets the containerView to the root UIWindow if the BarButtonItem is placed in a UINavigationBar.

It seems like UIWindow never rotates and is setting it's transformation instead.
http://lfhck.com/question/190884/after-rotation-uiview-coordinates-are-swapped-but-uiwindows-are-not

The popup is placed correctly but is not correctly rotated.

Then presentPointingAtView is called and that does a UIView* superView = containerView.superview, this retuned nil since keyWindow doesn't have any parent. superview is then used to convert between coordinate system. I tried to change this so that superView is set to containerview if nil but that didn't matter.

How to dim view

Hi,
is it possible to dim background (self.view not popTipView)?

Problems with nested view controllers

Great little component. But there seems to be some missing logic for use with view controllers within view controllers, with the popup either not appearing or appearing in the wrong location.

Flat background

How can I set up just a flat background color without gradient?
schermata 2015-03-31 alle 21 14 42

Already tried

popup.hasShadow = NO;
popup.has3DStyle = NO;

Pop tip stays highlighted when tapped

In touchesBegan you set highlight = YES, but it is never turned off, so it always appears highlighted from then on.

It seems you need a matching highlight = NO in finaliseDismiss.

doesn't compile with C++11

With a project with C++11 enabled the compiler give me error:
non-constant-expression cannot be narrowed from type 'double' to 'CGFloat' (aka 'float') in initializer list

line 151

CGFloat locationList[] = {0.0, bubbleMiddle-0.03, bubbleMiddle, bubbleMiddle+0.03, 1.0};

line 176

 CGFloat colorList[] = {
            //red, green, blue, alpha 
            red*1.16+colourHL, green*1.16+colourHL, blue*1.16+colourHL, alpha,
            red*1.16+colourHL, green*1.16+colourHL, blue*1.16+colourHL, alpha,
            red*1.08+colourHL, green*1.08+colourHL, blue*1.08+colourHL, alpha,
            red     +colourHL, green     +colourHL, blue     +colourHL, alpha,
            red     +colourHL, green     +colourHL, blue     +colourHL, alpha
        };

PopTip without pointing somewhere

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);

UIImageView's resetting to default frame when popup displayed

Hi, I thought I'd present this problem I'm having as someone might have an idea why it is happening. I'm having trouble figuring out why this is happening through the debugger.

  1. A UIImageView frame / size is being changed through a pinch gesture.
  2. I tap the UIImageView
  3. The Popup is displayed by the UIImageView's frame is reset to the initial frame size.

It should also be noted that the popup is being displayed as if the UIImageView is the new frame, not the original frame.

Any ideas would be appreciated - Thanks

Some PopTip views do not resize properly

I have three pop tip views in my application, two of them do not resize properly when they appear on screen:

1:
screen shot 2014-03-13 at 9 27 58 pm
2:
screen shot 2014-03-13 at 9 28 07 pm

3:
screen shot 2014-03-13 at 9 28 18 pm

They all have a title and message, 3D style is off.
Why is this?

How to distinguish between tips and button actions?

Hi Chris, thanks for this control. What do you suggest to do to distinguish a user's request for a tip, or a simple button tap? I would like to implement either a "rollover" or long gesture notification. But I don't want to go stomping around in your code. Am I overlooking something obvious? Thanks again.

Pop tip appears under table index

When a pop tip is presented from a bar button item on a table view, and that table view has an index, the table index draws over the tip:

see image

Also, the tip scrolls with the table view :)

Tooltip displayed in wrong position if container has non-zero origin

If your container view has non-zero origin, e.g.:

opt.view.bounds = CGRectMake(130, 130, 500, 490);

then the tooltip will sometimes be displayed at the wrong position. Fix is to replace this line:

CGFloat W = containerView.bounds.size.width;

with this:

CGFloat right = containerView.bounds.size.width+containerView.bounds.origin.x;

(and replace all occurrences of 'W' with 'right').

UIAlertView Dismissal Interfering with Animations

I don't know if this is really an issue or something I should have figured out right away. I am far from an animation expert.

I have a UIAlert that is posing options to a user. In the event of one option, I wanted to throw a PopTipView up and point it at a NavBarItem. The PopTipView was animating in and then disappearing right away.

The fix was very simple. In the clickedButtonAtIndex delegate method I executed a delayed selector instead of calling presentPointingAtBarButtonItem directly from the clickedButtonAtIndex method.

Its working now. Thank you so much! This control rocks!

Ability to add a buton outside of the tooltipview

I'm trying to create a button that overflows the tooltip like this:

screen shot 2015-02-27 at 14 19 30

But the touch event is not called for the upper part of the button. How can I make it work without modifying the library? I tried overriding pointInside:withEvent: but it doesn't get called.

I'm sorry if this doesn't regards this library directly but I can't figure it out how to do it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.