如何创建小费气球?

时间:2014-05-27 11:07:26

标签: ios

2 个答案:

答案 0 :(得分:2)

UITextField进行子类,然后覆盖becomeFirstResponder(显示气泡)和resignFirstResponder(隐藏气泡),当字段处于活动状态时,会显示您的气泡。

<强>·H

#import <UIKit/UIKit.h>

@interface BubbleTextField : UITextField

@end

<强>的.m

#import "BubbleTextField.h"

@interface BubbleTextField ()
{
    UIView *_bubbleView;
}

- (void)showBubble:(BOOL)show;

@end

@implementation BubbleTextField

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialize the _bubbleView here
    }
    return self;
}

#pragma mark - Override

- (BOOL)becomeFirstResponder {
    BOOL shouldBecome = [super becomeFirstResponder];

    if (shouldBecome)
    {
        [self showBubble:YES];
    }

    return shouldBecome;
}

- (BOOL)resignFirstResponder {
    BOOL shouldResign = [super resignFirstResponder];

    if (shouldResign)
    {
        [self showBubble:NO];
    }

    return shouldResign;
}

#pragma mark - Private Methods

- (void)showBubble:(BOOL)show {
    // Show/Hide
    // Animations etc.
}

@end

答案 1 :(得分:1)