我正在尝试制作一个具有类似 iOS 控制中心行为的 UIView。我当前的代码能够上拉显示和下拉隐藏。
#define kViewMaxHeight 600
#define kViewMinHeight 300
#define kViewWidth [[UIScreen mainScreen] bounds].size.width
#define kViewDefaultX 0
#define kScreenHeight [[UIScreen mainScreen] bounds].size.height
- (void)swipeView:(id)sender {
CGPoint location = [(UIPanGestureRecognizer *)sender locationInView:self];
CGPoint translatedPoint = [(UIPanGestureRecognizer *)sender translationInView:self];
CGPoint velocity = [(UIPanGestureRecognizer *)sender velocityInView:self];
NSLog(@"x:%.2f, y:%.2f", location.x, location.y);
if([(UIPanGestureRecognizer *)sender state] == UIGestureRecognizerStateBegan) {
firstX = [self center].x;
firstY = [self center].y;
}
translatedPoint = CGPointMake(firstX, firstY+translatedPoint.y);
// Dragged Up
if (velocity.y < 0) {
if (self.frame.origin.y + self.frame.size.height > kScreenHeight) {
[self setCenter:translatedPoint];
}
else {
}
}
// Dragged Down
else {
[self setCenter:translatedPoint];
}
//
if (self.frame.origin.y + self.frame.size.height < kScreenHeight) {
CGRect frame = self.frame;
frame.origin.y = kScreenHeight - kViewMinHeight;
self.frame = frame;
}
if ([(UIPanGestureRecognizer *)sender state] == UIGestureRecognizerStateEnded) {
if (velocity.y < 0 || location.y < 0) {
CGRect frame = self.frame;
frame.origin.y = kScreenHeight - kViewMinHeight;
self.frame = frame;
}
else {
CGRect frame = self.frame;
frame.origin.y = kScreenHeight - 50;
frame.size.height = kViewMinHeight;
self.frame = frame;
}
}
}
演示:
问题1: 任何人都可以举一些例子或指导我如何做到这一点?
问题2(这里有一些愚蠢的问题): iOS控制中心是如何实现的?是使用 UIViewController 还是 UIView?