chrismiles / CMPopTipView

Custom UIView for iOS that pops up an animated "bubble" pointing at a button or other view. Useful for popup tips.
https://github.com/chrismiles/CMPopTipView
MIT License
2.73k stars 467 forks source link

Bubble padding is no longer working in version 2.3.1 #132

Closed funnel20 closed 6 years ago

funnel20 commented 7 years ago

I just replaced version 2.3.0 by 2.3.1 and compiled my existing project in Xcode 8.3.3. The bubble is configured with sidePadding = 10.0.

When running it on an iPhone 7 with iOS 11.0.3 there is a big difference in padding.

Version 2.3.0 img_4735

Version 2.3.1 img_4736

The padding is no longer present. Please advise.

LuoyeAn commented 7 years ago

i am hitting it also.

funnel20 commented 7 years ago

The Release Notes of 2.3.1 are incomplete by only referring to:

Fixes issue in iOS 11 where tooltip would not display when presenting via a UIBarButtonItem.

When I look at the master, 2.3.0 was commit 176, while 2.3.1 is 199. So there are many more changes in 2.3.1. Commits 185 and 186 refer to a new property for padding. The change log of commit 186 https://github.com/chrismiles/CMPopTipView/commit/c9ab6ae6a408c8439530e062faacf7006e27982a shows indeed new property shouldEnforceCustomViewPadding. I see it's never initialised, except in initWithCustomView: which we don't use.

We have reverted back to 2.3.0. @TingtingAn Can you try with shouldEnforceCustomViewPadding = YES?

LuoyeAn commented 6 years ago

i have never to use initWithCustomView also

pventura1976 commented 6 years ago

Using sidePadding = 10.0 and shouldEnforceCustomViewPadding = YESworked for me in 2.3.1

funnel20 commented 6 years ago

@pventura1976 Thanks for confirming this. This seems to be a bug. Why is it required when setting property sidePadding to explicitly set shouldEnforceCustomViewPadding? At least there is a work-around now, but it doesn't make sense.

kleinlieu commented 6 years ago

Hey @FungusHumungus @pventura1976 I'm really sorry for the mistake. Perhaps I should have set shouldEnforceCustomViewPadding and sidePadding to be on by default in v2.3.2. What do you think?

funnel20 commented 6 years ago

@kleinlieu Thanks for your reaction. Before jumping to a solution; what is the purpose of new property shouldEnforceCustomViewPadding?

I would say that if a user wants to have padding, he defines sidePadding. If he uses property customView and wants padding, he defines both customView and sidePadding. For me it's not clear what shouldEnforceCustomViewPadding should control.

It seems to be some unnecessary BOOL introduced for the custom view. But in my opinion it can be completely deleted. It is now used as IF condition in - (CGRect)contentFrame and - (void)presentPointingAtView:(UIView *)targetView inView:(UIView *)containerView animated:(BOOL)animated. The IF condition can be replaced by: if (_sidePadding > 0) {

Do you agree?

UPDATE This probably won't work, as - (CGRect)contentFrame uses bubblePaddingX and bubblePaddingY, see my next comment. But then I don't understand why the padding works properly for @pventura1976 when shouldEnforceCustomViewPadding is set to YES.

funnel20 commented 6 years ago

Another over dimension seems to be the parameters bubblePaddingX and bubblePaddingY. What is the difference with sidePadding?

It would really help if all (less obvious) properties could have proper documentation in the header file. I bet that this would have prevented code implementation issues like this one. Because now there is clearly a misunderstanding of the meaning/definition of some properties. I'm happy to assist with this, but at least someone needs to explain these properties.

funnel20 commented 6 years ago

BTW, sidePadding is already set to a default value of 2.0 in - (id)initWithFrame:(CGRect)frame.

pventura1976 commented 6 years ago

I like this proposal

Best.

Pedro Ventura Gómez

El 17 nov 2017 21:50 +0100, funnel20 notifications@github.com, escribió:

BTW, sidePadding is already set to a default value of 2.0 in - (id)initWithFrame:(CGRect)frame. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

funnel20 commented 6 years ago

As mentioned before, we need to know the functionality first. I figured it out by playing around with the DEMO project.

IMPORTANT I was able to change sidePadding in the default DEMO project, where shouldEnforceCustomViewPadding is disabled. In order to see the proper effect of cornerRadius, bubblePaddingX and bubblePaddingY I had to enable shouldEnforceCustomViewPadding. Hence I changed the title if this issue from Property "sidePadding" to Bubble padding. It's worth noting that I was mistaking sidePadding with the inner bubble padding, i.e. the offset between the text and the bubble boundary. After playing around with the DEMO project I learned that this bubble padding is controlled by cornerRadius, bubblePaddingX and bubblePaddingY.

There are 5 properties playing a role:

  1. sidePadding This is the horizontal offset between the bubble and the view boundary: sidepadding The default value is 2. In the above screenshot it was set to 10.
  2. cornerRadius This will round the corners: cornerradius But it also increases the bubble around the text. See the difference with the previous image when increasing the value: cornerradius40 The default value is 10.
  3. bubblePaddingX bubblepaddingx This is the horizontal offset between the bubble text and the bubble boundary: IMPORTANT: When cornerRadius >0 it's added to bubblePaddingX, so the horizontal offset is the total of both properties. The default value is 0. When this value >0, the horizontal bubble size increases.
  4. bubblePaddingY This is the vertical offset between the bubble text and the bubble boundary: bubblepaddingy IMPORTANT: When cornerRadius >0 it's added to bubblePaddingY, so the vertical offset is the total of both properties. The default value is 0. When this value >0, the vertical bubble size increases.
  5. shouldEnforceCustomViewPadding This seems to be an unnecessary internal property which currently causes this issue that bubble padding is not working.
funnel20 commented 6 years ago

SOLUTION Now that the functionality of all involved properties is clear, the solution seems simple:

  1. Remove property shouldEnforceCustomViewPadding
  2. In - (CGRect)contentFrame, the complete IF-ELSE can removed, as the IF statement should always be performed, as it contains all the 3 discussed properties: cornerRadius, bubblePaddingX and bubblePaddingY:

    - (CGRect)contentFrame {
    CGRect bubbleFrame = [self bubbleFrame];
    
    CGRect contentFrame = CGRectMake(bubbleFrame.origin.x + _cornerRadius + _bubblePaddingX,
                                     bubbleFrame.origin.y + _cornerRadius + _bubblePaddingY,
                                     bubbleFrame.size.width - (_bubblePaddingX*2) - (_cornerRadius*2),
                                     bubbleFrame.size.height - (_bubblePaddingY*2) - (_cornerRadius*2));
    return contentFrame;
    }
  3. Similar in - (void)presentPointingAtView:(UIView *)targetView inView:(UIView *)containerView animated:(BOOL)animated the IF condition should always be performed, so remove IF-ELSE:
    _bubbleSize = CGSizeMake(textSize.width + (_bubblePaddingX*2) + (_cornerRadius*2), textSize.height + (_bubblePaddingY*2) + (_cornerRadius*2));

Verification I have verified the DEMO project after these 3 changes and now the bubble padding does properly work without changing anything to the DEMO code.

Recommendations

  1. Why does cornerRadius automatically apply bubble padding? This is not common, see for example cornerRadius of CALayer. If for a larger cornerRadius bubble padding is necessary, this can be configured via bubblePaddingX and bubblePaddingY.
  2. Properly document each property in the header file.
  3. Be accurate with the Release Notes. The Release Notes of 2.3.1 are incomplete by only referring to an iOS 11 fix for the tooltip on a UIBarButtonItem. When looking at the master, it appears that there are many more changes in 2.3.1. Even new properties such as the erroneous shouldEnforceCustomViewPadding and it's code that caused this issue.
funnel20 commented 6 years ago

I have created a pull request with the solution. Should I make another with more documentation in the header file?

funnel20 commented 6 years ago

This is resolved as 2.3.2