Skip to content
This repository was archived by the owner on Jul 17, 2024. It is now read-only.

Library doesn't seem to be working as it should #9

Open
adamdahan opened this issue Mar 4, 2015 · 20 comments
Open

Library doesn't seem to be working as it should #9

adamdahan opened this issue Mar 4, 2015 · 20 comments
Assignees
Labels

Comments

@adamdahan
Copy link

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

@adamdahan
Copy link
Author

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

@mgcm
Copy link
Owner

mgcm commented Mar 5, 2015

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?

@adamdahan
Copy link
Author

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

@adamdahan adamdahan changed the title So this library doesn't work anymore. Library doesn't seem to be working as it should Mar 5, 2015
@adamdahan
Copy link
Author

Changed my issue to something more appropriate *

@adamdahan
Copy link
Author

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
Copy link
Author

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
Copy link
Author

Do you think its just a Swift compatibility issue?

@SuperTango
Copy link

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
Copy link

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.

@oflannabhra
Copy link

@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.

@diakonovm
Copy link

@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.

@pjebs
Copy link

pjebs commented Feb 25, 2016

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.

@mgcm
Copy link
Owner

mgcm commented Feb 25, 2016

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 mgcm self-assigned this Feb 25, 2016
@mgcm mgcm added the bug label Feb 25, 2016
@pjebs
Copy link

pjebs commented Feb 25, 2016

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
Copy link

pjebs commented Feb 26, 2016

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
Copy link

pjebs commented Feb 26, 2016

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

@TimE90
Copy link

TimE90 commented Mar 7, 2016

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

@hyd00
Copy link

hyd00 commented Mar 18, 2016

SAME PROBLEM :(

@marcelodbi
Copy link

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?

@pjebs
Copy link

pjebs commented Apr 16, 2016

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;

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

No branches or pull requests

9 participants