2015-10-14 93 views
-2

我想说明其中含有的UITableView为顶视图,它会显示张贴的用户& 的UITextField用按钮下方将进入评论沿着评论&上添加它到后,我有一个观点在facebook应用程序中看到,当我按下评论按钮时弹出出现。所以我怎么能achhieve在这是最好的方式。我知道我可以通过在动画中添加一个视图在父视图中。但那会导致我添加更多&更多的自定义代码。是否有任何其他方式可以实现这一目标? some thing like this如何在iOS中弹出评论框?

+0

为您的概念使用textview –

+0

我在这里谈论如何显示弹出 – Techiee

+0

您是否在寻找iPhone或iPad的解决方案?对于iPad,有现有的API,您可以在其中以模态方式呈现视图控制器。但iPhone不存在,您需要使用第三方库或您自己的库。 – GoodSp33d

回答

0

如果是为iPad(如右图),尝试创建一个新UIViewController,并从当前的viewController模态呈现,但在UIModalPresentationStyle属性设置为UIModalPresentationFormSheet

+0

如果设备不是ipad会如何显示在iPhone上 – Techiee

2

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

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

和开源的iOS库

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

尝试任何一个,一个巨大的图书馆希望它可以帮助你。

UPDATE编程

添加这些属性: -

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

@synthesize他们。

SETUP弹出与阴影效应: - 弹出鉴于

-(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; 

} 

内容; -

-(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方法点击按钮或在文本框上。作为你的需要。

+0

如果我不想使用第三方库,该怎么办?我想模态地呈现视图控制器 – Techiee

+0

Apple(现有API)不支持iPhone上的模式视图控制器。 – GoodSp33d

+0

好吧,您可以使用uiPopOverController来显示弹出窗口,并且您还可以使用弹出式动画以编程方式添加视图。 –