我正在构建我的键盘扩展应用程序,并且当用户点击它时,我在按钮上添加了按键弹出动画。它适用于内部图像,但顶行图像弹出区域在剪辑子视图时变得隐藏。我尝试使用 ClipToBound 属性并将其设置为 False。但仍然无法正常工作。有人知道如何解决这个问题吗?在超级视图上添加子视图也不起作用。
图像 A 显示正确的弹出窗口,因为它位于键盘框架内。图像 B 错误,因为在框架内弹出剪辑。
我正在构建我的键盘扩展应用程序,并且当用户点击它时,我在按钮上添加了按键弹出动画。它适用于内部图像,但顶行图像弹出区域在剪辑子视图时变得隐藏。我尝试使用 ClipToBound 属性并将其设置为 False。但仍然无法正常工作。有人知道如何解决这个问题吗?在超级视图上添加子视图也不起作用。
图像 A 显示正确的弹出窗口,因为它位于键盘框架内。图像 B 错误,因为在框架内弹出剪辑。
我认为您不允许在键盘视图之外显示任何内容;它会被自动剪裁。
//那些正在寻找弹出形状图像的人:
// 我使用了一些按钮宽度等常量,您可以根据新键盘进行调整。
**#define _UPPER_WIDTH (52.0 * [[UIScreen mainScreen] scale])
**#define _LOWER_WIDTH (32.0 * [[UIScreen mainScreen] scale])
**#define _PAN_UPPER_RADIUS (7.0 * [[UIScreen mainScreen] scale])
**#define _PAN_LOWER_RADIUS (7.0 * [[UIScreen mainScreen] scale])
**#define _PAN_UPPDER_WIDTH (_UPPER_WIDTH-_PAN_UPPER_RADIUS*2)
**#define _PAN_UPPER_HEIGHT (61.0 * [[UIScreen mainScreen] scale])
**#define _PAN_LOWER_WIDTH (_LOWER_WIDTH-_PAN_LOWER_RADIUS*2)
**#define _PAN_LOWER_HEIGHT (30.0 * [[UIScreen mainScreen] scale])
**#define _PAN_UL_WIDTH ((_UPPER_WIDTH-_LOWER_WIDTH)/2)
**#define _PAN_MIDDLE_HEIGHT (11.0 * [[UIScreen mainScreen] scale])
**#define _PAN_CURVE_SIZE (7.0 * [[UIScreen mainScreen] scale])
**#define _PADDING_X (15 * [[UIScreen mainScreen] scale])
**#define _PADDING_Y (10 * [[UIScreen mainScreen] scale])
**#define _WIDTH (_UPPER_WIDTH + _PADDING_X*2)
**#define _HEIGHT (_PAN_UPPER_HEIGHT + _PAN_MIDDLE_HEIGHT + _PAN_LOWER_HEIGHT + _PADDING_Y*2)
**#define _OFFSET_X -25 * [[UIScreen mainScreen] 比例])
**#define _OFFSET_Y 59 * [[UIScreen mainScreen] scale])
- (UIImage *)createKeytopImageOfType:(ButtonType)type
{
CGMutablePathRef path = CGPathCreateMutable();
CGPoint p = CGPointMake(_PADDING_X, _PADDING_Y);
CGPoint p1 = CGPointZero;
CGPoint p2 = CGPointZero;
p.x += _PAN_UPPER_RADIUS;
CGPathMoveToPoint(path, NULL, p.x, p.y);
p.x += _PAN_UPPDER_WIDTH;
CGPathAddLineToPoint(path, NULL, p.x, p.y);
p.y += _PAN_UPPER_RADIUS;
CGPathAddArc(path, NULL,
p.x, p.y,
_PAN_UPPER_RADIUS,
3.0*M_PI/2.0,
4.0*M_PI/2.0,
false);
p.x += _PAN_UPPER_RADIUS;
p.y += _PAN_UPPER_HEIGHT - _PAN_UPPER_RADIUS - _PAN_CURVE_SIZE;
CGPathAddLineToPoint(path, NULL, p.x, p.y);
p1 = CGPointMake(p.x, p.y + _PAN_CURVE_SIZE);
switch (type)
{
case LeftButton:
p.x -= _PAN_UL_WIDTH*2;
break;
case InnerButton:
p.x -= _PAN_UL_WIDTH;
break;
case RightButton:
break;
}
p.y += _PAN_MIDDLE_HEIGHT + _PAN_CURVE_SIZE*2;
p2 = CGPointMake(p.x, p.y - _PAN_CURVE_SIZE);
CGPathAddCurveToPoint(path, NULL,
p1.x, p1.y,
p2.x, p2.y,
p.x, p.y);
p.y += _PAN_LOWER_HEIGHT - _PAN_CURVE_SIZE - _PAN_LOWER_RADIUS;
CGPathAddLineToPoint(path, NULL, p.x, p.y);
p.x -= _PAN_LOWER_RADIUS;
CGPathAddArc(path, NULL,
p.x, p.y,
_PAN_LOWER_RADIUS,
4.0*M_PI/2.0,
1.0*M_PI/2.0,
false);
p.x -= _PAN_LOWER_WIDTH;
p.y += _PAN_LOWER_RADIUS;
CGPathAddLineToPoint(path, NULL, p.x, p.y);
p.y -= _PAN_LOWER_RADIUS;
CGPathAddArc(path, NULL,
p.x, p.y,
_PAN_LOWER_RADIUS,
1.0*M_PI/2.0,
2.0*M_PI/2.0,
false);
p.x -= _PAN_LOWER_RADIUS;
p.y -= _PAN_LOWER_HEIGHT - _PAN_LOWER_RADIUS - _PAN_CURVE_SIZE;
CGPathAddLineToPoint(path, NULL, p.x, p.y);
p1 = CGPointMake(p.x, p.y - _PAN_CURVE_SIZE);
switch (kind) {
case PKNumberPadViewImageLeft:
break;
case PKNumberPadViewImageInner:
p.x -= _PAN_UL_WIDTH;
break;
case PKNumberPadViewImageRight:
p.x -= _PAN_UL_WIDTH*2;
break;
}
p.y -= _PAN_MIDDLE_HEIGHT + _PAN_CURVE_SIZE*2;
p2 = CGPointMake(p.x, p.y + _PAN_CURVE_SIZE);
CGPathAddCurveToPoint(path, NULL,
p1.x, p1.y,
p2.x, p2.y,
p.x, p.y);
p.y -= _PAN_UPPER_HEIGHT - _PAN_UPPER_RADIUS - _PAN_CURVE_SIZE;
CGPathAddLineToPoint(path, NULL, p.x, p.y);
p.x += _PAN_UPPER_RADIUS;
CGPathAddArc(path, NULL,
p.x, p.y,
_PAN_UPPER_RADIUS,
2.0*M_PI/2.0,
3.0*M_PI/2.0,
false);
//----
CGContextRef context;
UIGraphicsBeginImageContext(CGSizeMake(_WIDTH,
_HEIGHT));
context = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(context, 0.0, _HEIGHT);
CGContextScaleCTM(context, 1.0, -1.0);
CGContextAddPath(context, path);
CGContextClip(context);
//----
// draw gradient
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceGray();
CGFloat components[] = {
0.95f, 1.0f,
0.85f, 1.0f,
0.675f, 1.0f,
0.8f, 1.0f};
size_t count = sizeof(components)/ (sizeof(CGFloat)* 2);
CGRect frame = CGPathGetBoundingBox(path);
CGPoint startPoint = frame.origin;
CGPoint endPoint = frame.origin;
endPoint.y = frame.origin.y + frame.size.height;
CGGradientRef gradientRef =
CGGradientCreateWithColorComponents(colorSpaceRef, components, NULL, count);
CGContextDrawLinearGradient(context,
gradientRef,
startPoint,
endPoint,
kCGGradientDrawsAfterEndLocation);
CGGradientRelease(gradientRef);
CGColorSpaceRelease(colorSpaceRef);
CGImageRef imageRef = CGBitmapContextCreateImage(context);
UIImage * image = [UIImage imageWithCGImage:imageRef scale:[[UIScreen mainScreen] scale] orientation:UIImageOrientationDown];
CGImageRelease(imageRef);
UIGraphicsEndImageContext();
CFRelease(path);
return image;
}
@Ben 是正确的,您不能在键盘窗口之外显示任何内容。
如果您检查视图层次结构,您会发现UIWindow
持有键盘扩展并没有延伸到键盘上方,因此即使您关闭clipsToBounds
整个视图层次结构直到窗口,您仍然无法在窗口之外显示。