我正在构建我的键盘扩展应用程序,当用户点击它时,我在按钮上添加了关键的流行动画。它适用于内部图像,但顶部图像弹出区域在剪切子视图时会隐藏。我尝试使用ClipToBound属性并设置为False。但仍然没有工作。任何人都知道如何解决这个问题?在superview上添加子视图也行不通。
图像A显示正确弹出,因为它在键盘框内。图像B错误,因为框内弹出剪辑。
答案 0 :(得分:5)
我不认为你可以在键盘视图之外显示任何内容;它会自动剪裁。
答案 1 :(得分:4)
//正在寻找弹出形状图像的人:
//我已经使用了一些常量作为按钮宽度等,你可以根据新键盘进行调整。
** #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] scale])
** #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;
}
答案 2 :(得分:1)
@Ben是正确的,您不允许在键盘窗口外显示任何内容。
如果您检查视图层次结构,则可以看到持有键盘扩展名的UIWindow
不会延伸到键盘上方,因此即使您在整个视图层次结构中关闭clipsToBounds
也是如此到窗口,你仍然无法在窗外显示。