MMPopLabel icon indicating copy to clipboard operation
MMPopLabel copied to clipboard

Library doesn't seem to be working as it should

Open adamdahan opened this issue 9 years ago • 20 comments

Basically your popAtView function doesn't pop at the right place.

adamdahan avatar Mar 04 '15 23:03 adamdahan

im running iOS 8 in an app that takes advantage auto layout and storyboards

adamdahan avatar Mar 04 '15 23:03 adamdahan

I have tested this pod with Xcode 6.1.1, iOS 8 and AutoLayout and I am getting no issues. Can you provide an example?

mgcm avatar Mar 05 '15 12:03 mgcm

Ya when I get a chance today ill share a link to some sample code.

adamdahan avatar Mar 05 '15 14:03 adamdahan

Changed my issue to something more appropriate *

adamdahan avatar Mar 05 '15 14:03 adamdahan

Ok so I am starting to think that I might have just jumped the gun trying to bridge your project into my swift project.

But here is the basics,

I put this sample in my viewDidLoad

*********************** BEGINNING OF CODE SNIPPET *****************

MMPopLabel.appearance().labelColor = UIColor.blueColor() MMPopLabel.appearance().labelTextColor = UIColor.whiteColor() MMPopLabel.appearance().labelTextHighlightColor = UIColor.greenColor() MMPopLabel.appearance().labelFont = UIFont.systemFontOfSize(14.0) MMPopLabel.appearance().buttonFont = UIFont.systemFontOfSize(16.0)

popLabel = MMPopLabel(text: "Some Text")

let skipButton = UIButton(frame: CGRectZero) skipButton.setTitle("Skip", forState: .Normal)

self.view.addSubview(popLabel) popLabel.popAtView(avatarImageView)

*********************** END OF CODE SNIPPET *****************

My AvatarImageView is sitting in the dead center of the screen. And the popLabel appears where my leftBarButtonItem is.

Is there something I am missing?

adamdahan avatar Mar 09 '15 15:03 adamdahan

Even if I put the code to viewDidLayoutSubviews (aka after AutoLayout has done is calculations for frames) it still does not pop at the right place.

adamdahan avatar Mar 09 '15 15:03 adamdahan

Do you think its just a Swift compatibility issue?

adamdahan avatar Mar 09 '15 15:03 adamdahan

I'm definitely having a similar problem (swift project, XCode-6.1.1), but I haven't had time to delve into it too deeply.

The popup label is defined like this:

    var passwordErrorLabel: MMPopLabel!

My view hierarchy is:

RootView (self.view)
  UIScrollView (self.scrollView)
     UITextView (self.passwordTextField)

Everything except for the passwordErrorLabel is setup via the storyboard, using AutoLayout.

Then in viewDidLoad():

        MMPopLabel.appearance().labelColor = UIColor.blueColor()
        MMPopLabel.appearance().labelColor = textFieldErrorBackgroundColor
        MMPopLabel.appearance().labelTextColor = UIColor.whiteColor()
        MMPopLabel.appearance().labelTextHighlightColor = UIColor.redColor()
        MMPopLabel.appearance().labelFont = buttonFont
        MMPopLabel.appearance().buttonFont = buttonFont

        passwordErrorLabel = MMPopLabel(text: "Password must be at least 8 characters")

        self.scrollView.addSubview(passwordErrorLabel)
        // I also tried: 
        // self.view.addSubview(passwordErrorLabel) with the same results.

If the user's pw doesn't meet the password policy criteria, I call (from within func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool:

    self.passwordErrorLabel.popAtView(self.passwordTextField)

The screen looks like this:

image

Does it have anyhthing to do with the passwordTextField not being in the root hierarchy directly or in a scrollview?

SuperTango avatar Mar 23 '15 20:03 SuperTango

It's something with the first part of popAtView():

    if ([[view superview] superview] != self.window) {
        center = [self.window convertPoint:view.center fromView:view];
    }

If I comment this out, it works properly.

SuperTango avatar Mar 23 '15 21:03 SuperTango

@SuperTango I can confirm the exact same behavior.

Xcode 6.3 - Objective C

center is getting translated by convertPoint: from x:338.5, y:644 to x:656.5, y:1273

The view hierarchy is

UIWindow
|-UILayoutContanerView
  |-UINavigationTransitionView
    |-UIViewControllerWrapperView
      |-UIView
        |-UIButton (view)

Could it be that all of the transition views automatically created by AutoLayout are creating difficulties for this test?

Commenting out the same section of code works for me.

oflannabhra avatar Apr 15 '15 14:04 oflannabhra

@SuperTango Confirmed. It took me a bit to figure this out, should have checked the open issues, but removing this fixed the positioning problems on the iPad.

diakonovm avatar May 18 '15 07:05 diakonovm

I'm having the same issue. The MMPopLabel was originally covering the view. Then later it is started popuping up way below the view similar to the image above.

How can I fix it.

The view is controlled by autolayout. I am on a ipad.

pjebs avatar Feb 25 '16 05:02 pjebs

For a quick fix, try changing the following code in MMPopLabel.m, line 204:

CGPoint center = view.center; if ([[view superview] superview] != self.window) { center = [self.window convertPoint:view.center fromView:view]; } self.center = center;

with this:

self.center = [view.superview convertPoint:view.center toView:[UIApplication sharedApplication].keyWindow.rootViewController.view]; CGPoint center = self.center;

This should solve your problem. I'll be updating the pod ASAP with this change.

mgcm avatar Feb 25 '16 22:02 mgcm

I'll check if the workaround works and let you know. However there is another bug.

My PopLabel doesn't have any buttons. Just text. I want it to dismiss when I tap on the PopLabel.

I don't think - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event works.

It takes many many many taps and it's totally predictable on when it does dismiss.

pjebs avatar Feb 25 '16 23:02 pjebs

Here is a fix:

Inside : - (id)initWithText:(NSString *)text

add: [self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss)]];

Inside : - (void)addButton:(UIButton *)button

add:

[self.gestureRecognizers enumerateObjectsUsingBlock:^(__kindof UIGestureRecognizer * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
    obj.enabled = NO;
}];
[self.buttons addObject:button];

pjebs avatar Feb 26 '16 01:02 pjebs

Could you please add those in and then the class should be all good.

pjebs avatar Feb 26 '16 01:02 pjebs

We have the same problem with the position of the label.. but your workaround does not work :(

TimE90 avatar Mar 07 '16 18:03 TimE90

SAME PROBLEM :(

hyd00 avatar Mar 18 '16 07:03 hyd00

The fix from "mgcm" coment worked for me!!! I'm having a issue to change the text to display multiples tips. I didnt find any text property. Anyone give me a hint?

marcelodbi avatar Apr 02 '16 13:04 marcelodbi

CASE CLOSED:

This guy's fork solves the problem: https://github.com/kouheiszk/MMPopLabel

if (view.superview != self.superview) {
+        center = [self.superview convertPoint:center fromView:view.superview];
     }
     self.center = center;

pjebs avatar Apr 16 '16 08:04 pjebs