如何在iOS中弹出评论框作为弹出窗口?

时间:2015-10-14 05:36:42

标签: ios objective-c iphone uitableview ipad

我希望将包含 UITableView 的视图显示为顶视图,该视图将显示用户发布的评论& UITextField 以及下方的按钮将输入评论&把它添加到帖子上,我在facebook应用程序中看到,当我按下评论按钮时会出现一个弹出窗口。所以我怎么能理解它的最佳方式。我知道我可以通过在父母中添加一个视图来实现查看动画。但这将引导我添加更多&更多的自定义代码。我还有其他方法可以实现这个吗?some thing like this

3 个答案:

答案 0 :(得分:2)

PopUp上有太多的库,您可以根据需要添加。 最好的是 -

1。https://github.com/jmascia/KLCPopup

和一个用于开源iOS库的庞大库

2。https://www.cocoacontrols.com/search?q=popup

尝试任何一个,希望它能帮到你。

程序化更新

添加以下属性: -

@property (strong, nonatomic) UIView *container;
@property (strong, nonatomic) UIView *pop;

@synthesize他们。

设置带阴影效果的PopUp: -

-(void)setViewPop{
    _container  = [[UIView alloc] initWithFrame:self.view.frame];
    [self.view addSubview:_container];
    //self.backgroundDimmingView = [self buildBackgroundDimmingView];
    //[self.container addSubview:self.backgroundDimmingView];

    pop = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height , self.view.frame.size.width-80, self.view.frame.size.height/1.5-40 )];
    pop.backgroundColor = [UIColor orangeColor];
    pop.layer.cornerRadius = 10;

    UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:pop.bounds];
    pop.layer.masksToBounds = NO;
    pop.layer.shadowRadius = 5;
    pop.layer.shadowColor = [UIColor whiteColor].CGColor;
    pop.layer.shadowOffset = CGSizeMake(0.0f, 5.0f);
    pop.layer.shadowOpacity = 0.5f;
    pop.layer.shadowPath = shadowPath.CGPath;

    [self.container addSubview:pop];
    [self setUpPop];

    pop.center = self.container.center;

}

popUp视图的内容; -

-(void)setUpPop{
    self.pop.frame = CGRectMake(0, 0, self.view.frame.size.width-80, self.view.frame.size.height/1.5-40 );


    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(90, 10, 100, 20)];
    title.textColor = [UIColor whiteColor];
    title.textAlignment = NSTextAlignmentCenter;
    title.text = @"Choose Date";

    [self.pop addSubview:title];

    UIButton *cancelbutton = [[UIButton alloc] initWithFrame:CGRectMake(0,self.pop.frame.size.height-40, self.pop.frame.size.width/2, 40)];
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:cancelbutton.bounds byRoundingCorners:( UIRectCornerBottomLeft) cornerRadii:CGSizeMake(10.0, 10.0)];

    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.view.bounds;
    maskLayer.path  = maskPath.CGPath;
    cancelbutton.layer.mask = maskLayer;
    cancelbutton.backgroundColor = [UIColor lightGrayColor];
    [cancelbutton setTitle:@"Cancel" forState:UIControlStateNormal];
    [cancelbutton addTarget:self
                     action:@selector(cancelbuttonTapped:)
           forControlEvents:UIControlEventTouchUpInside];
    [pop addSubview:cancelbutton];

    UIButton *confirmbutton = [[UIButton alloc] initWithFrame:CGRectMake(140, self.pop.frame.size.height-40,self.pop.frame.size.width/2, 30)];
    UIBezierPath *maskPath1 = [UIBezierPath bezierPathWithRoundedRect:confirmbutton.bounds byRoundingCorners:( UIRectCornerBottomRight) cornerRadii:CGSizeMake(10.0, 10.0)];

    CAShapeLayer *maskLayer1 = [[CAShapeLayer alloc] init];
    maskLayer1.frame = self.view.bounds;
    maskLayer1.path  = maskPath1.CGPath;
    confirmbutton.layer.mask = maskLayer1;

    confirmbutton.backgroundColor = [UIColor orangeColor];
    confirmbutton.alpha=0.8f;
    [confirmbutton setTitle:@"set Date" forState:UIControlStateNormal];
    [pop addSubview:confirmbutton];

}

这是显示视图的动画; -

- (void)showPopUp{

    _container.transform = CGAffineTransformMakeScale(0.01, 0.01);
    [UIView animateWithDuration:0.5f delay:0 usingSpringWithDamping:0.7f initialSpringVelocity:3.0f options:UIViewAnimationOptionAllowAnimatedContent  animations:^{
        _container.transform = CGAffineTransformIdentity;
        [self setViewPop];
    } completion:^(BOOL finished){
        // do something once the animation finishes, put it here
    }];

}

按钮单击或在文本字段上调用-(void)showPopUp方法。根据你的需要。

答案 1 :(得分:0)

如果适用于iPad(如图所示),请尝试创建新的UIViewController并从当前的viewController以模态方式呈现它,但将UIModalPresentationStyle属性设置为UIModalPresentationFormSheet

答案 2 :(得分:0)

有许多第三方库。  你可以看看其中的一些。 http://www.code4app.net/category/popupview

我个人会推荐CTPopOutMenu。 http://www.code4app.net/ios/his-control-is-like-an-UIAlertView-with-button-icon-and-four-basic-layout/54fd4759e24741fd64073341

我使用它,它对我来说就像一个魅力。 快乐编码.. :)