[英]How to make images in WKInterfacePicker Transparent?
I have a WKInterfacePicker which is set to Sequence mode. 我有一个WKInterfacePicker设置为序列模式。 When i add images to it during runtime and display it on the apple watch, the images seems to have a black background (instead of having the transparent pixels).
当我在运行时向其添加图像并将其显示在Apple Watch上时,图像似乎具有黑色背景(而不是透明像素)。 The Images have transparent pixels in them.
图像中有透明像素。 Here is the code i used in willActivate function:
这是我在willActivate函数中使用的代码:
NSMutableArray *pItems = [[NSMutableArray alloc] initWithCapacity:31];
for(int i=0; i<30; ++i){
WKPickerItem *item = [[WKPickerItem alloc] init];
WKImage *img = nil;
if(i < 10)
img = [WKImage imageWithImageName:[NSString stringWithFormat:@"safeDial_0%d", i]];
else
img = [WKImage imageWithImageName:[NSString stringWithFormat:@"safeDial_%d", i]];
[item setContentImage:img];
[pItems addObject:item];
}
[self.pickerSafeLock setItems:[pItems copy]];
[self.pickerSafeLock setSelectedItemIndex:0];
[self.pickerSafeLock focus];
Note: pickerSafeLock is the WKInterfacePicker 注意:pickerSafeLock是WKInterfacePicker
Also, when i use the same images on a WKImage, i see that the transparent pixels work fine. 另外,当我在WKImage上使用相同的图像时,我看到透明像素工作正常。
Is there a way to make the Images in WKInterfacePicker transparent? 有没有办法使WKInterfacePicker中的图像透明?
After trying multiple ways (including @DaGaMs's solution), i found an considerably tricky solution to the problem. 在尝试了多种方法(包括@DaGaMs的解决方案)之后,我发现了一个相当棘手的问题解决方案。 I have used a WKInterfacePicker and an associated WKInterfaceImage alongside it.
我使用了WKInterfacePicker和关联的WKInterfaceImage。 Here is a way to overcome the issue:
这是解决问题的一种方法:
In the Storyboard of your WatchKit App add a WKinterfaceImage, WKInterfaceGroup and WKInterfacePicker inside a WKInterfaceGroup. 在WatchKit应用程序的Storyboard中,在WKInterfaceGroup内添加WKinterfaceImage,WKInterfaceGroup和WKInterfacePicker。
Here is how it would look: 外观如下:
This is just to hide the Picker offscreen, so that we can fake the animation from the Picker to the WKInterfaceImage. 这只是为了将Picker隐藏在屏幕外,以便我们可以将动画从Picker伪装到WKInterfaceImage。
Once you do this, on the IBAction of WKInterfacePicker set the corresponding images like this: 完成此操作后,在WKInterfacePicker的IBAction上设置相应的图像,如下所示:
- (IBAction)pickerAction:(NSInteger)value {
[self.yourWKInteraceImage setImage:imgPickerList[value]];
}
Note: imgPickerList contains all the images that you want to animate (same as the Picker). 注意:imgPickerList包含要设置动画的所有图像(与Picker相同)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.