使用Tabbarcontroller时出现问题

时间:2016-05-28 06:13:19

标签: ios swift uitabbarcontroller tabbar

我正在使用带有四个tabbarItem的TabbarController。但我的要求是Tabbar显示在viewController的Top上,这样就完成了。但问题是在viewcontroller上添加dropdownview时Tabbar隐藏了下拉列表。请帮帮我

enter image description here

我的viewController类代码

   import UIKit

  class TrendingVC: UIViewController,DropDownViewDelegate
 {
   @IBOutlet var btndropdown: UIButton!
   var dropdown = DropDownView()
   override func viewDidLoad() {
    super.viewDidLoad()

 dropdown = dropdown.initWithArrayData(["1111111111","222222222","3233333333","33333333333","1222333333"], cHeight: 30, tableviewHight: 150, tPaddingTop:0, tPaddingLeft: 0, tPaddingRight: 0, refView: btndropdown, tAnimation:AnimationType.GROW, openAnimationDuration: 0.5, closeAnimationDuration: 0.5, Dropdowncolor: UIColor.purpleColor(), DropdowntextColor: UIColor.whiteColor(), DropdowntextSize: 17) as! DropDownView

    dropdown.delegate = self;

    self.view.addSubview(dropdown.view);
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func DropDownCellSelected(index: NSInteger)
{
    print(index);
}
@IBAction func btndropdownclik(sender:UIButton!)
{
     self.view.bringSubviewToFront(dropdown.view)
    dropdown.OpenAnimation()

}

我的自定义下拉类代码      导入UIKit

 enum AnimationType
 {
   case  BLENDIN
   case  GROW
   case  BOTH
  }
   protocol DropDownViewDelegate
   {
      func DropDownCellSelected(index:NSInteger) -> Void
   }
   class DropDownView:          UIViewController,UITableViewDelegate,UITableViewDataSource
   {
   var arrDropDown = NSMutableArray()
   var delegate: DropDownViewDelegate!
   var OPENAnimationDuration,CLOSEAnimationDuration,DropdownViewTextsize,CellHight,DropDownHight,LeftMargin,RightMargin,TopMargin:CGFloat!
var refillview:UIView!
var DropdownViewColor,DropDownviewTextcolor:UIColor!
var animationType:AnimationType!
var tbl:UITableView!

override func viewDidLoad()
{
    super.viewDidLoad()


    let refFrame:CGRect = refillview.frame;

    tbl = UITableView();
    tbl.frame = CGRectMake(0, 0, refFrame.size.width+RightMargin, (animationType == AnimationType.BOTH||animationType == AnimationType.BLENDIN) ?DropDownHight:1)
    tbl.dataSource = self;

    tbl.delegate = self;
    //uiTableView.backgroundColor=[UIColor colorWithRed:15/255 green:41/255 blue:63/255 alpha:1];
    tbl.backgroundColor = UIColor.clearColor()
    self.view.addSubview(tbl)
    self.view.hidden = true;
    if (animationType == AnimationType.BOTH || animationType == AnimationType.BOTH)
    {
        self.view.alpha = 1;
    }
}

override func didReceiveMemoryWarning()
{
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

// MARK: - Tableview Methods

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return arrDropDown.count;
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    return 1;
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
    let cellidentifier:NSString = "CellId";
    var cell:UITableViewCell? = tableView.dequeueReusableCellWithIdentifier(cellidentifier as String)
    if  cell==nil
    {
        cell = UITableViewCell.init(style: UITableViewCellStyle.Default, reuseIdentifier: cellidentifier as String)
    }
    cell!.backgroundColor = UIColor.purpleColor();
    cell!.textLabel?.text = arrDropDown.objectAtIndex(indexPath.row) as? String
    cell!.selectionStyle = UITableViewCellSelectionStyle.None;
    cell!.textLabel?.font = UIFont(name:"helvetica" , size: 20)

    return cell!
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
{

    return CellHight;
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
    self.CloseAnimation()
    delegate.DropDownCellSelected(indexPath.row)

}
func OpenAnimation()
{
    self.view.hidden = false

    //var newCenter:CGPoint = CGPointMake(playAgainButton.center.x, playAgainButton.center.y + 200)
    UIView.beginAnimations(nil, context: nil)
    UIView.setAnimationDuration(1.0)
    tbl.frame = CGRectMake(tbl.frame.origin.x,tbl.frame.origin.y,tbl.frame.size.width, DropDownHight);
    UIView.commitAnimations()

}
func CloseAnimation()
{
    self.view.hidden = false;

    UIView.beginAnimations(nil, context: nil)
    UIView.setAnimationDuration(1.0)
    tbl.frame = CGRectMake(tbl.frame.origin.x,tbl.frame.origin.y,tbl.frame.size.width, 0);
    UIView.commitAnimations()
}
func OpenAnimationWithRef()
{


}
func initWithArrayData(data:NSArray,cHeight:CGFloat,tableviewHight:CGFloat,tPaddingTop:CGFloat,tPaddingLeft:CGFloat,tPaddingRight:CGFloat,refView:UIView!,tAnimation:AnimationType,openAnimationDuration:CGFloat,closeAnimationDuration:CGFloat,Dropdowncolor:UIColor!,DropdowntextColor:UIColor!,DropdowntextSize:CGFloat) -> AnyObject
{
        arrDropDown=data.mutableCopy() as! NSMutableArray;
        CellHight = cHeight;
        DropDownHight = tableviewHight;
        TopMargin = tPaddingTop;
        LeftMargin = tPaddingLeft;
        RightMargin = tPaddingRight;
        refillview = refView;
        OPENAnimationDuration = openAnimationDuration;
        CLOSEAnimationDuration = closeAnimationDuration;
        animationType = tAnimation;
        DropdownViewColor = Dropdowncolor;
        DropDownviewTextcolor = DropdowntextColor;
        DropdownViewTextsize = DropdowntextSize;

    let reframe = refView.frame;
    self.view.frame = CGRectMake(reframe.origin.x-LeftMargin, reframe.origin.y+reframe.size.height+TopMargin, reframe.size.width+RightMargin,DropDownHight);
    self.view.layer.shadowColor = UIColor.clearColor().CGColor
    self.view.layer.shadowOffset = CGSizeMake(5.0, 5.0)
    self.view.layer.shadowOpacity = 1.0;
    self.view.layer.shadowRadius = 5.0;
    tbl.layer.cornerRadius = 5.0;
    tbl.layer.borderWidth = 3.0;
    tbl.layer.borderColor = UIColor.darkGrayColor().CGColor;
    tbl.autoresizingMask = UIViewAutoresizing.FlexibleWidth;
        return self
    }


/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
}
*/

}

0 个答案:

没有答案