我在iPad应用程序中遇到了横向模式的问题.
我创建了一个非常小的新项目来显示我的问题我将pList中的UIInterfaceOrientation设置为UIInterfaceOrientationLandscapeRight
在app delegate中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window makeKeyAndVisible];
MyController *myController = [[MyController alloc] init];
[self.window addSubview:myController.view];
return YES;
}
Run Code Online (Sandbox Code Playgroud)
在MyController中
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSLog(@"Bounds Height:%f %f", self.view.bounds.size.height, self.view.bounds.size.width);
}
Run Code Online (Sandbox Code Playgroud)
我也试过在viewDidLoad中使用相同的结果
如果我在横向保持设备的同时启动应用程序NSLog输出
Bounds Height: 1004.000000 Bounds Width: 768.000000
Run Code Online (Sandbox Code Playgroud)
我需要做些什么才能获得正确的结果?我是这个iOS编程的新手,我要做的就是将UISlider锚定到屏幕的底部,但是当我得到不正确的坐标时,我不确定该怎么做.
我有一个NSView,用户可以在其中绘制圆圈.这些圆圈存储为NSBezierPaths数组,在drawRect:中,我遍历数组并调用-stroke每个路径.如何添加按钮来放大和缩小NSView?只是改变视图的界限?
谢谢.
什么是CALayer(如layerUIView上的属性所示)以及我们在哪里使用这样的类?
我有一个带有1的故事板UIViewController,持有1 UIView包含许多嵌套的UIViews.我将View Controller子类化为实现此方法:
- (BOOL)shouldAutorotateToInterfaceOrientation: UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
Run Code Online (Sandbox Code Playgroud)
我还补充道
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIInterfaceOrientation</key>
<string>UIInterfaceOrientationLandscapeLeft</string>
Run Code Online (Sandbox Code Playgroud)
到了Info.plist.
在主UIView的viewDidLoad中我这样做:
PASectionView* sectionView = [[PASectionView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, 180)];
[self addSubview:sectionView];
Run Code Online (Sandbox Code Playgroud)
问题是控制只有756像素宽而不是预期的1024.有关详细信息,请参阅下面的屏幕截图.
我一直在网上搜索,但我无法找到解决这个令人沮丧的问题的方法.我正在使用Xcode 4.5和iOS5.1设置为基本SDK.
编辑 它通过用边界替换框架来工作.但是我不明白发生了什么,所以它不适用于帧大小.
我看到很多代码解释了如何在视图中居中子视图.代码示例通常如下所示:
SubView.center = view.center;
Run Code Online (Sandbox Code Playgroud)
有人可以向我解释这是如何工作的吗?我只是不明白.
在view.center给出了视图的中心点.例如,宽度为100,高度为100,它将返回(50,50).我知道了.
设置subview.center对我来说很奇怪. subview.center将返回子视图的中心点.不知何故,将其设置为(50,50)会将子视图定位在其父级中,坐标为50/50.但是如果子视图本身宽度为50且高度为50,则访问此属性将返回let(),然后返回(25,25).
我的意思是什么?这里的概念对我来说很奇怪,因为setter和getter正在做不同的功能.
如果有人可以解释这个,请做.或者,如果我离开基地,我也想知道.我是iOS开发的新手.
如果我是正确的,这确实是它的工作方式,你不会认为这是一种反模式.当然,在.NET中,这样的东西就是反模式.也许不适合Obj-C?
我有一个 Swift 应用程序,它将 UIImageView 设置为屏幕一部分的大小(使用自动约束设置为其上方的边距和控件),并且我使用 ImageView 的高度和宽度值以编程方式创建 3 个额外的 UIImageViews 并定位它们位于原始图像之上。我正在建造一个讲台并将三张图像放在讲台顶部的适当位置。然后我计算的高度和通过创建一个恒定的宽度的每个附加图像的:let conImageHeight = 0.4 * self.imgPodium.frame.height。但是,我无法获得原始图像的可靠高度和宽度。
最初我使用self.imgPodium.bounds.heightwhich 非常适合 iPhone 6 模拟器屏幕尺寸,但是当我尝试在 iPad 模拟器上运行该应用程序时,它保留了 iPhone 尺寸值。图像本身改变了大小,但是当我使用println()的高度和宽度时bounds,我得到了 iPhone 图像的值。
然后我改变并使用了self.imgPodium.frame.height但这并没有改变任何东西。
在通过自动约束定位自己后,是否有更好的方法来获取 UIImageView(或任何与此相关的控件)的高度和宽度?
谢谢。
我已经看过但没有帮助的问题:
在 Swift 中
以编程方式更改 UIImageView 大小和位置如何在 swift
UIImageView Bounds、Frame
Cocoa 中以编程方式检查 iphone 4 和 iphone 5 的屏幕大小:框架和边界之间有什么区别?
如何调整 UIImageView 的大小 (swift)
在这段代码中
CGRect contextRect = self.bounds;
会参考哪个界限?rectangle,imageRect或整个iOS视图.
我试图使用quartz2D来操作图像,我通过查看不同的示例来创建此代码,并且在//之间编写的代码来自Apple Quartz2D指南绘制文本.
在此先感谢,问候.
- (void)drawRect:(CGRect)rect
{
CGSize cgs = CGSizeMake(250.0, 400.0);
UIGraphicsBeginImageContext(cgs);
CGRect rectangle = CGRectMake(0,0,cgs.width,cgs.height);
CGRect imageRect = CGRectInset(rectangle, 5.4, 5.4);
imageRect.size.height -= 100;
UIImage *myImage = [UIImage imageNamed:@"pumpkin.jpg"];
[myImage drawInRect:imageRect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(context, 10.0);
CGContextSetRGBStrokeColor(context, 0.0, 0.0, 1.0, 1.0);
CGContextStrokeRect(context, rectangle);
//
CGRect contextRect = self.bounds;
CGContextTranslateCTM(context, 0, contextRect.size.height);
CGContextScaleCTM(context, 1, -1);
float w, h;
w = contextRect.size.width;
h = contextRect.size.height;
CGAffineTransform myTextTransform;
CGContextSelectFont (context, "Helvetica-Bold", h/10, kCGEncodingMacRoman);
CGContextSetCharacterSpacing (context, …Run Code Online (Sandbox Code Playgroud) 我想在UIScrollView中获取UIButton的位置问题是,当UIButton位于其原始位置或向下滚动时,我得到相同的位置...
我正在使用NSLog打印位置,我得到相同的输出
没有向下滚动我得到...
2014-11-05 19:28:02.564 ... {{260, 163}, {370, 225}}
Run Code Online (Sandbox Code Playgroud)即使我向下滚动,我也得到相同的输出......
2014-11-05 19:28:06.052 ... {{260, 163}, {370, 225}}
Run Code Online (Sandbox Code Playgroud)这是我使用获得的位置代码的UIButton里面的UIScrollView ...
NSLog(@"%@", NSStringFromCGRect(CGRectMake(myButton.frame.origin.x, myButton.frame.origin.y, myScrollDown.frame.size.width, myScrollDown.frame.size.height)));
Run Code Online (Sandbox Code Playgroud)
有一种方法可以在我向下滚动后获得UIButton的实际位置?
还有另一种方法可以在ScrollView中获取UIButton的位置吗?
我已经访问了以下链接,但我还没有解决它.
iPhone - 在整个UIWindow中获取UIView的位置
谢谢你的帮助!
我在Swift做了一个简单的游戏,我试图找到一个很好的方法来获得游戏场景的中心.目前我正在这样做:
CGPoint(x: size.width / 2, y: size.height / 2)
Run Code Online (Sandbox Code Playgroud)
看起来很简单.但是,在检查时,我发现这四件事也作为GameScene类的一部分存在:
self.frame
self.size
self.view.bounds
self.view.frame
Run Code Online (Sandbox Code Playgroud)
我很困惑.我应该使用哪一个?它们对我来说都是一样的.有什么不同?
ios ×6
objective-c ×6
cocoa ×3
iphone ×2
swift ×2
appkit ×1
cocoa-touch ×1
ipad ×1
macos ×1
nsscrollview ×1
nsview ×1
uibutton ×1
uiimageview ×1
uikit ×1
uiscrollview ×1
xamarin.ios ×1
xcode ×1