Tag: uiview

在CGRectZero中使用autoResizingMask

我正在build立一个tableview部分的页脚。 页脚的高度将在heightForFooterInSection指定,所以在viewForFooterInSection我想只是添加子视图,并指定页脚视图应填充任何页脚高度指定(此页脚大小将dynamic)。 因此,我使用CGRectZero作为初始框架并告诉页脚视图展开以填充其父视图。 – (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { UIView *footerView = [[UIView alloc] initWithFrame:CGRectZero]; footerView = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; footerView = [UIColor greenColor]; return footerView; } 这按预期工作 – 表视图的页脚完全填充绿色视图。 但是现在我想添加一个UITextView到页脚。 文本视图应填充相同的空间,但留下5点边界: { UIView *footerView = [[UIView alloc] initWithFrame:CGRectZero]; footerView = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; footerView = [UIColor greenColor]; UITextView *textView = [[UITextView alloc] initWithFrame:CGRectInset(footerView.frame, 5, […]

在Swift中,在运行时更改Autolay约束UIView的框架

例如,我使用这段代码来改变名为Propo的UIView的框架位置: self.Propo.frame.origin.x -= self.view.frame.width ( Propo在Storyboard中有约束) 但是,当应用程序视图消失并重新出现时, UIView会将其自身重置为原来的位置。 我该如何解决呢? 我想让UIView保持其位置,当我改变它的编程。 我已经尝试updateViewConstraints()的东西附加…

从XIB文件实例化一个UIView作为文件的所有者?

比方说,我有一个XIB文件(MyView.xib)包含一个单一的根UIView其类是一些自定义的UIView子类(MyView)。 我想从XIB文件创buildMyView的实例(在代码中),但我也希望文件的所有者是MyView的实例(这样我可以将IBOutlets从XIB链接到代码)。 换句话说,MyView是XIB中的根视图的类,它也被设置为文件的所有者类。 我在MyView实现中尝试了这样的事情: – (id)initFromNib { self = [[[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:nil] firstObject]; return self; } 然后我意识到这是没有道理的,因为那时候self是零,所以文件的所有者被设置为零(不好)。 这开始感觉像鸡蛋问题,因为我需要文件的所有者是在创build之前即将创build的实例。 然后我尝试了这样的事情: – (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:CGRectMake(0.0, 0.0, 310, 166)]; if (self) { self = [[[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:nil] firstObject]; } return self; } 显然这只是一个临时的黑客,看看它是否会起作用,但是不行。 该视图被加载并正确显示,但是当我按下其中一个button(具有相关联的IBAction)时,该应用程序崩溃。 我错过了什么明显的? 或者是我的理解有某种缺陷? 一般的问题是,我只想拥有一个包含该视图的可视化表示的关联XIB的自定义UIView子类,并且还希望能够在XIB和其对应的UIView子类之间关联IBOutlets。 任何和所有的build议是受欢迎的。

以模态方式呈现UIImagePickerController时出错

我有一个奇怪的问题,在iOS 6应用程序中以模态方式呈现UIImagePickerController 。 XCode给我这个错误: Warning: Attempt to present <UIImagePickerController: 0x1e025040> on <UINavigationController: 0x1d51ce00> whose view is not in the window hierarchy! 我在我的AppDelegate有以下窗口层次结构: – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window = window; firstViewController = [[SGNewMailViewController alloc] init]; navController = [[UINavigationController alloc] initWithRootViewController:firstViewController]; self.window.rootViewController = firstViewController; [self.window makeKeyAndVisible]; return […]

UIView内的UIButton Target Action

我有一个自定义的UIView我在其中创build了一个UIButton 。 在这个视图里面,我有这样的代码: func setupViews() { menuControlButton.addTarget(self, action: "toggleButton:", forControlEvents: .TouchUpInside) } func toggleButton(sender: MenuControlButton!) { let isActive = sender.toggleActive() // switches button image and returns whether active or not after NSUserDefaults.standardUserDefaults().setBool(isActive, forKey: sender.title) someOtherViewController.reloadCalendar() } 这是一个不好的做法吗? 特别是因为我通过自定义UIView调用另一个控制器的function。 我应该这样做,所以这些方法在ViewController? 还是有更好的方法来做到这一点?

StoreKit的SKStoreProductViewController离开导航栏和视图之间的空间?

我有这个UIViewController的子类,它显示了一个SKStoreProductViewController 。 这个视图控制器最初是为iOS 5创build的,并没有使用自动布局。 我的问题是,当提供SKStoreProductViewController时,导航栏和实际内容之间有一个空格…如果您滚动视图,分段控件(详细信息/评论/相关)浮动在导航栏下方(请参阅下面的图像,我添加了一个面具的图像,使问题更加明显)。 由于我们无法访问所呈现的视图控制器,我猜测它与呈现SKStoreProductViewController的控制器SKStoreProductViewController 。 当用户点击显示控制器的button时,我试图改变/移动视图的框架,我也做了一些像self.navigationController.navigationBar.translucent = NO; 但似乎没有任何帮助。 有没有人有类似的问题? 任何想法如何解决它?

多个UIView的重叠

我在自定义UIView's创build多个自定义UIView 。 自定义子视图的创build是可以的。 他们看起来像这样: 绘制方法非常简单: [[UIColor brownColor] set]; CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(ctx, 5.0f); CGContextBeginPath(ctx); CGContextMoveToPoint(ctx, 0.0f, 0.0f); CGContextAddLineToPoint(ctx, 100.0f, 0.0); CGContextAddLineToPoint(ctx, 130.0f, 25.0f); CGContextAddLineToPoint(ctx, 100.0f, 50.0f); CGContextAddLineToPoint(ctx, 0.0f, 50.0f); CGContextClosePath(ctx); CGContextStrokePath(ctx); [super drawRect:rect]; 将它添加到超级视图也很简单: ITContextFigure *view = [[ITContextFigure alloc] initWithFrame:CGRectMake(location.x, location.y, 135.0f, 50.0f)]; [view setBackgroundColor:[UIColor yellowColor]]; [self addSubview:view]; 所以我的问题是: 1)如何检测一个与另一个重叠? 我看到这个解决scheme: if (CGRectContainsRect([myImageView1 frame], […]

自定义MKMapView标注不响应触摸事件

我有一个自定义的UIView ,当用户点击一个MKMapView上的自定义注释时,将显示为一个标注。 为了实现这个我已经subclassed MKAnnotationView并重载-setSelected:selected animated:方法build议在这个答案 。 基本上,我添加我的自定义视图作为我的MKAnnotationView子类的子视图。 问题是我无法与包含button和可滚动webview的标注进行交互。 更重要的是,如果标注隐藏了注释,而且我在该隐藏注释的大概位置按下标注,则标注将被解除,并显示新标注。 // TPMapAnnotationView.m @implementation TPMapAnnotationView – (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; if(selected) { TPMapAnnotation* anno = ((TPMapAnnotation*)self.annotation); QuickInfoView* qi = [[QuickTabView alloc] initWithFrame:CGRectMake(0, 0, 440, 300)]; [qi displayDataForAnnotation:anno]; [self addSubview:qi]; // some animiation code that doesn't change things either way } else { [[self.subviews objectAtIndex:0] removeFromSuperview]; […]

iOS – CALayer和手势/滑动识别器

我添加了一个图层到我的视图来创build渐变背景颜色,但我需要在我的视图中使用UISwipeGestureRecognizer。 问题是,现在,与图层,刷卡识别器不起作用! 我能怎么做?? 我可以添加滑动识别器到图层吗? 谢谢

查看背景颜色和button图像具有相同的代码,但不同的外观(iOS)

我通过故事板为UIView设置背景颜色,但是在模拟器中看到更亮的颜色。 它与Button图像背景不同,代码相同,代码草图相同。 阿尔法设置1.什么可能是错的?