iOS 7.1问题 – 触摸并拖动该选项卡button时,Tabbar图标图像会自动resize
我有这个代码
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"tab_pressed_home_icon"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_home_icon"]]; tabBarItem1.imageInsets = UIEdgeInsetsMake(8, 0, -2, 0);
在标签栏上设置一个图标。
一切工作罚款到目前为止,直到昨晚我更新Xcode 5.1
并在ios7.1模拟器上运行该应用程序。
这里是应用程序
现在当我点击标签栏图标图像的大小是减less当我释放手指图像恢复正常。 但是,如果我点击图标并拖动图像看起来像这样(缩小)。
喜欢这个
这怎么可能发生? 反正有解决这个问题吗?
谢谢。
通过设置tabBarItem的imageInsets像其他人提到的那样解决了这个问题。 您可以在代码中执行此操作,也可以在Interface Builder中执行此操作,这并不重要。
重要的一点是顶部插入BE EQUAL到底部插入。
我尝试通过如下代码设置图像插入时,在iOS 7.1上遇到同样的问题:
[self.tabBarItem setImageInsets:UIEdgeInsetsMake(5, 0, -5, 0)];
所以我直接用我的故事板上的条形物尺寸来解决它。
请记住,为了这个工作,你应该以下面的方式分配你的TabBarItem的图像
UITabBar *tabBar = self.tabBarController.tabBar; UITabBarItem *myItem = [tabBar.items objectAtIndex:0]; [homeItem setFinishedSelectedImage:[UIImage imageNamed:@"A.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"B.png"]];
而不是这样
[self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"A.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"B.png"]];
更新
要访问“条形图大小”,请直接在“任何选项卡条形图控制器”的子项的“场景”下select“项目”元素。 (图像1)
我的问题是类似的,Tabbar的图标改变了它在7.1更新的位置,这个问题真的很烦人,我做了一个快速的解决scheme,因为我必须批准的应用程序。 是这样的:
好吧,我不确定这是最好的解决scheme,但对我来说,工作。
这里同样的问题。 同样在更新到iOS 7.1和xcode 5.1之后我的解决scheme:标签栏项目大小设置为4(底部)(在大小检查器中)我像其他人一样将其更改为0,问题消失了。
我放弃了,我的解决办法在这里:
使用该函数resize并使用UIImage
进行偏移
- (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize andOffSet:(CGPoint)offSet{ UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0); [image drawInRect:CGRectMake(offSet.x, offSet.y, newSize.width-offSet.x, newSize.height-offSet.y)]; UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return newImage; }
并正确设置标签栏项目图像:
UITabBarItem *barItem = [self.tabBarController.tabBar.items objectAtIndex:i]; CGSize size = CGSizeMake(49, 49); CGPoint offset = CGPointMake(10, 10); [barItem setFinishedSelectedImage:[self imageWithImage:selectedImage scaledToSize:size andOffSet:offset] withFinishedUnselectedImage:[self imageWithImage:unSelectedImage scaledToSize:size andOffSet:offset]];
如果有其他解决scheme将是帮助!
你可以把一个UIView放在标签栏的顶部,并添加一个UITapGestureReognizer到UIView。 点击时,我确定它在哪里,并为标签栏调用适当的选定项目。 黑客,但工作相当不错,让你保持你的插图价值任何你想要的。
@property UIView tabBarCover;//place on top of uitabbar and give it clear color background - (void)viewDidLoad { [tabBar setSelectedItem:[tabBar.items objectAtIndex:0]]; UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)]; [tabBarCover addGestureRecognizer:singleFingerTap]; }
然后每次点击UIView时,根据用户的触摸位置设置选定的项目。 我有3个标签栏项目,所以我只是做了一些逻辑的X坐标。
-(void) handleSingleTap:(UITapGestureRecognizer *) recognizer { CGPoint location = [recognizer locationInView:[recognizer.view superview]]; //NSLog(@"tapped it %lf", location.x); if(location.x<=105){ //1st 3rd tapped, do something } else if(location.x >105 && location.x<=210) { //do nothing, selected item stays same. this is glas }else{ //must be in 3rd section so do that load } }
希望能帮助到你。
我花了大约3个小时! 我发现我们的错误。 这不是iOS的错误。
注意:imageInsets不会帮助! 因为这是图像尺度的问题。 我玩了2个小时! 没有结果。 这是愚蠢的方式来尝试解决问题!
请看这个项目http://www.raywenderlich.com/50310/storyboards-tutorial-in-ios-7-part-2
在这个项目上玩家和手势图标完美的作品! 因为有视网膜和非视网膜的图标。
如果你有两个规模的图标,那么没有问题。 使用它们! 一切都会正常工作! 这是1变种!
2变。 如果您只有一个大图像,并且您想同时使用这两个图像,则需要指定resize的图像的“比例”:
(UIImage *)thumbnailImageSize:(CGSize)size fromImage:(UIImage *)image { if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] == YES && [[UIScreen mainScreen] scale] == 3.00) { _scale = 3.00; } else if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] == YES && [[UIScreen mainScreen] scale] == 2.00) { _scale = 2.00; } else _scale = 1.00; UIGraphicsBeginImageContextWithOptions(size, NO, _scale); [image drawInRect:CGRectMake(0, 0, size.width, size.height)]; UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return newImage; }
我的回答是基于其他人张贴在这里 – 设置为0标签栏项目中的所有ImageInsets:
for (UITabBarItem* item in self.tabBar.items) { [item setImageInsets: UIEdgeInsetsMake(0, 0, 0, 0)]; }
试试这个,它应该做的伎俩,不会影响旧版本
将下面的行放在任何控制器init方法中:
UIImage* image = [UIImage imageNamed: @"Your tabbar image name goes here"]; if ([image respondsToSelector: @selector(imageWithRenderingMode:)]) [self.tabBarItem setImage: [image imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal]];
顶部和底部的插入在你的代码中设置 – 它应该足以刚刚设置这些(例如,顶部)。 突出显示的图像被压缩的原因可能是光栅具有不同的尺寸,与默认图像不一样 – 在这种情况下,插图使图像垂直缩放。
我通过使用这个类别的UIImage,从UIView创build一个图像解决了同样的问题
+ (UIImage *) imageWithView:(UIView *)view { UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0); [view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage * img = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return img; }
然后,使用这种方法,你可以用你需要的自定义偏移量创build一个新的图像。 (我只需要Y偏移量)。
-(UIImage *) uiNewImageForTabBar: (UIImage *) i withOffsetForY: (CGFloat) offsetY { UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, i.size.width, i.size.height+offsetY)]; [v setBackgroundColor:[UIColor clearColor]]; [v setOpaque:NO]; UIImageView *sub = [[UIImageView alloc] initWithImage:i]; [sub setY:offsetY]; [v addSubview:sub]; return [UIImage imageWithView:v]; }
- 使用CSS和jQuery轻触发光示例,享受
- iOS 11.0中不推荐使用“自动调整ScrollViewInsets”
- 使用Objective-C查找IMEI号码
- NSFetchedResultsController在合并“NSManagedObjectContextDidSaveNotification”后没有显示所有结果
- 使用简洁的NSManagedObjectID URIforms?
- UISearchControllerDelegate – 搜索栏在表头中不可见
- IOS的iPhone 4s不重绘dynamic图像,最初是在视口之外
- 设备旋转后的iOSbutton点击区域
- 如何在Google地图上添加3d对象作为标记,就像Uber一样