我有一个需要首页的项目,当用户滚动时时,它将显示。所以我在public class FirebaseHelper {
DatabaseReference db;
Boolean saved=null;
ArrayList<String> spacecrafts=new ArrayList<>();
Context context;
public FirebaseHelper(DatabaseReference db,Context context) {
this.db = db;
this.context = context;
}
//WRITE
public Boolean save(Spacecraft spacecraft)
{
if(spacecraft==null)
{
saved=false;
}
else
{
try
{
db.child("Spacecraft").push().setValue(spacecraft);
saved=true;
}catch (DatabaseException e)
{
e.printStackTrace();
saved=false;
}
}
return saved;
}
//READ
public ArrayList<String> retrieve()
{
db.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
fetchData(dataSnapshot);
Toast.makeText(context, "callMe", Toast.LENGTH_SHORT).show();
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
fetchData(dataSnapshot);
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
return spacecrafts;
}
private void fetchData(DataSnapshot dataSnapshot)
{
spacecrafts.clear();
for (DataSnapshot ds : dataSnapshot.getChildren())
{ String name=ds.getValue(Spacecraft.class).getName();
spacecrafts.add(name);
}
}
}
中创建了两个单独的ViewController
,如下所示:
storyboard
中的我将工作表视图控制器添加为子视图,如下所示:
ViewController
然后我有一个let topSheet = self.storyboard?.instantiateViewController(withIdentifier: "top_sheet_vc") as! TopSheetVC
self.addChildViewController(topSheet)
self.view.addSubview(topSheet.view)
topSheet.didMove(toParentViewController: self)
topSheet.view.translatesAutoresizingMaskIntoConstraints = false
let height = NSLayoutConstraint(item: topSheet.view, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: Constant.TOP_SHEET_HEIGHT)
let leading = NSLayoutConstraint(item: topSheet.view, attribute: .leading, relatedBy: .equal, toItem: self.view, attribute: .leading, multiplier: 1.0, constant: 0)
let trailing = NSLayoutConstraint(item: topSheet.view, attribute: .trailing, relatedBy: .equal, toItem: self.view, attribute: .trailing, multiplier: 1.0, constant: 0)
let bottom = NSLayoutConstraint(item: topSheet.view, attribute: .bottom, relatedBy: .equal, toItem: self.view, attribute: .top, multiplier: 1.0, constant: 0)
NSLayoutConstraint.activate([height, leading, trailing, bottom])
附加到主视图控制器的主视图,并且在处理程序方法中我可以移动视图以便可以显示顶部工作表,如下所示:
UIPanGestureRecognizer
到目前为止一切顺利,顶层显示并变得可见,主视图正如我预期的那样向下移动。
问题是首页不是互动且可点击,我无法弄清楚这有什么问题。
所以任何帮助或提示都会受到赞赏。
提前tnx。 注意:如果我为func panGestureHappened(recognizer: UIPanGestureRecognizer) {
let y = self.view.frame.minY
let translation = recognizer.translation(in: self.view)
let min = fmin(y + translation.y, Constant.TOP_SHEET_HEIGHT)
self.view.transform = CGAffineTransform(translationX: 0, y: min)
// or I can change the frame, same result as CGAffineTransform
// self.view.frame = CGRect(x: CGFloat(0), y: min, width: self.view.frame.width, height: self.view.frame.height)
}
而不是基本视图设置动画,那么顶部工作表TopSheet
基本视图,而不是向下移动基本视图问题将是已消失且overlap
可点击。但我无法弄明白为什么。
更新:我消除了所有自定义约束,并在故事板内的主控制器中添加了TopSheet
,并且容器具有负值,顶部将其带到外面,当主要视图得到动画并且顶部显示但它仍然无法点击,但如果我覆盖容器它再次变为可点击,那么有什么相关的视图高度,任何想法?