iphone - 为什么不设置 UIView 框架?

标签 iphone ios xcode uiview

我正在尝试一些微不足道的事情!无法相信它不起作用!也许我忽略了什么! 我的 iPhone 应用程序中有一个主页。我现在想添加一个 subview ,它最初将在屏幕之外(即隐藏在右侧,即它的 frame.origin.x 将是屏幕宽度),然后我想通过翻转动画它进入页面的动画 -水平并部分显示 subview (大约只有半个屏幕)。

[self.mySubview.view setFrame:CGRectMake([[UIScreen mainScreen] bounds].size.width, 0.0,
                                                 [[UIScreen mainScreen] bounds].size.width,
                                                 [[UIScreen mainScreen] bounds].size.height)];
[self.view addSubview:self.mySubview.view];
NSLog(@"frame before x %f", self.mySubview.view.frame.origin.x);

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
      [self.mySubview.view setFrame:CGRectMake([[UIScreen mainScreen] bounds].size.width*(2/5), 0.0,
                                                       [[UIScreen mainScreen] bounds].size.width,
                                                       [[UIScreen mainScreen] bounds].size.height)];
[UIView commitAnimations];
NSLog(@"frame x %f", self.mySubview.view.frame.origin.x);

我正在尝试在 iPad 上运行它。但是 subview 的框架最初并未设置为 768.0。此外,动画没有发生。动画前后,subview的frame.origin.x只有0.0。我哪里可能出错了?请帮忙。我尝试改变 Storyboard 中的自动调整大小的箭头(删除它们,添加它们)......似乎没有任何效果!

最佳答案

试试这个

   Someviewcontroller *c = initWithNibName
     c.view.frame = CGRectMake(0, 0, 200, 200);
     [self addSubView:c];

关于iphone - 为什么不设置 UIView 框架?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16034785/

相关文章:

iphone - 获取非英文字符作为英文字符

iPhone - UILabel 同时包含多种字体的文本

ios - enumerateBodiesAlongRayStart 在 Xcode 6 中打印 "Chance"到控制台

iPhone Wifi 扫描 Sumbler

xcode - 在协议(protocol)扩展中调用默认方法的问题

ios - 无法在 Xcode 6 中构建 iOS 应用程序

iphone - 在 peoplePickerNavigationController 中选择联系人后呈现 viewController?

iphone - Restkit 覆盖本地实体更改

iphone - 避免手势链频繁测试 iPhone App 代码的方法

ios - 在 iPhone 开机或关机时发送通知