我有一个视图控制器层次结构,最顶层的控制器显示为模态,并想知道如何在使用时显示导航栏
'UIViewController:presentViewController:viewControllerToPresent:animated:completion'
Run Code Online (Sandbox Code Playgroud)
'presentViewController的文档:动画:完成:'注意:
'在iPhone和iPod touch上,呈现的视图始终为全屏.在iPad上,演示文稿取决于modalPresentationStyle属性中的值.
对于'modalPresentationStyle',文档说:
演示样式确定如何在屏幕上显示模态呈现的视图控制器.在iPhone和iPod touch上,模态视图控制器始终以全屏显示,但在iPad上有几种不同的显示选项.
一旦视图控件显示自己,是否有办法确保导航栏在状态栏下方可见?我应该将文档解释为,你没有获得iPhone/iPod的任何选项,只能在iPad上?
以前,我使用的'UIViewController:presentModalViewController:animated'工作正常,但自iOS 5.0以来,API已被弃用,因此我转而使用新版本.
在视觉上,我要做的是从屏幕底部开始使用新控制器,就像过去使用的旧API一样.
[用代码更新]:
// My root level view:
UIViewController *vc = [[RootViewController alloc]
initWithNibName:nil
bundle:[NSBundle mainBundle]];
navController = [[UINavigationController alloc] initWithRootViewController:vc];
....
// Within the RootViewController, Second view controller is created and added
// to the hierarchy. It is this view controller that is responsible for
// displaying the DetailView:
SecondTierViewController *t2controller = [[SecondTierViewController alloc]
initWithNibName:nil
bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:t2controller animated:YES];
// Created by SecondTierViewController
DetailViewController *controller = …Run Code Online (Sandbox Code Playgroud) iphone uiviewcontroller modalviewcontroller presentmodalviewcontroller ios
在ARC之前,如果我想要一个属性只读它而在课堂上可写,我可以这样做:
// Public declaration
@interface SomeClass : NSObject
@property (nonatomic, retain, readonly) NSString *myProperty;
@end
// private interface declaration
@interface SomeClass()
- (void)setMyProperty:(NSString *)newValue;
@end
@implementation SomeClass
- (void)setMyProperty:(NSString *)newValue
{
if (myProperty != newValue) {
[myProperty release];
myProperty = [newValue retain];
}
}
- (void)doSomethingPrivate
{
[self setMyProperty:@"some value that only this class can set"];
}
@end
Run Code Online (Sandbox Code Playgroud)
使用ARC,如果我想覆盖setMyProperty,则不能再使用retain/release关键字,这是否足够正确?
// interface declaration:
@property (nonatomic, strong, readonly) NSString *myProperty;
// Setter override
- (void)setMyProperty:(NSString *)newValue
{
if (myProperty != newValue) { …Run Code Online (Sandbox Code Playgroud) 我正在尝试取消然后释放暂停的计时器但是当我调用'dispatch_release'时,我立即得到EXC_BAD_INSTRUCTION.
这不是一组有效的计时器吗?
定时器创建和暂停:
@interface SomeClass: NSObject { }
@property (nonatomic, assign) dispatch_source_t timer;
@end
// Class implementation
@implementation SomeClass
@synthesize timer = _timer;
- (void)startTimer
{
dispatch_queue_t globalQ = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
self.timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER,
0, 0, globalQ);
dispatch_time_t startWhen = dispatch_walltime(DISPATCH_TIME_NOW, NSEC_PER_SEC * 1);
dispatch_source_set_timer(_timer, startWhen, 1 * NSEC_PER_SEC, 5000ull);
dispatch_source_set_event_handler(_timer, ^{
// Perform a task
// If a particular amount of time has elapsed, kill this timer
if (timeConstraintReached)
{
// Can I suspend this timer within it's own …Run Code Online (Sandbox Code Playgroud) 我有一个带有许多子视图的UIView和一个被认可的Tap手势,我想模仿它具有"触摸"效果.也就是说,当点击发生时,我想显示容器视图具有不同的背景颜色,并且任何子视图UILabel的文本也看起来突出显示.
当我从UITapGestureRecognizer收到tap事件时,我可以很好地改变背景颜色甚至将UILabel设置为 [label setHighlighted:YES];
由于各种原因,我无法将UIView更改为UIControl.
但是如果我添加一些UIViewAnimation来恢复突出显示,则没有任何反应.有什么建议?
- (void)handleTapGesture:(UITapGestureRecognizer *)tapGesture {
[label setHighlighted:YES]; // change the label highlight property
[UIView animateWithDuration:0.20
delay:0.0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
[containerView setBackgroundColor:originalBgColor];
[label setHighlighted:NO]; // Problem: don't see the highlight reverted
} completion:^(BOOL finished) {
// nothing to handle here
}];
}
Run Code Online (Sandbox Code Playgroud) 我想知道是否有一种方法可以动画第一个视图,UIPageViewController以便它看起来像一个页面角落有点晃动?当你第一次到达这个特定的屏幕时,好像有一阵微风拂过页面.
这可以添加某种UI功能,以指示可以刷屏幕.我们正在显示的内容UIPageViewController并不像书本那样占据整个屏幕,但是想让用户更清楚他们可以使用手势来横向导航.
任何的意见都将会有帮助.
我有一个返回a的类方法CGSize,我想通过Objective-C运行时函数调用它,因为我将类和方法名称作为字符串值.
我正在使用XCode 4.2中的ARC标志进行编译.
方法签名:
+(CGSize)contentSize:(NSString *)text;
Run Code Online (Sandbox Code Playgroud)
我尝试的第一件事是用objc_msgSend这样调用它:
Class clazz = NSClassFromString(@"someClassName);
SEL method = NSSelectorFromString(@"contentSize:");
id result = objc_msgSend(clazz, method, text);
Run Code Online (Sandbox Code Playgroud)
这与"EXC_BAD_ACCESS"崩溃并且没有堆栈跟踪.我首先使用了这个,因为文档objc_msgSend说,
当遇到一个方法调用,编译器生成到的功能之一的呼叫
objc_msgSend,objc_msgSend_stret,objc_msgSendSuper,或objc_msgSendSuper_stret.[...]使用objc_msgSendSuper_stret和发送具有数据结构作为返回值的方法objc_msgSend_stret.
接下来,我用objc_msgSend_stret这样的:
Class clazz = NSClassFromString(@"someClassName);
SEL method = NSSelectorFromString(@"contentSize:");
CGSize size = CGSizeMake(0, 0);
objc_msgSend_stret(&size, clazz, method, text);
Run Code Online (Sandbox Code Playgroud)
使用上面的签名给出了以下两个编译器错误和两个警告:
错误:自动引用计数问题:ARC不允许将非Objective-C指针类型'CGSize*'(又名'struct CGSize*')隐式转换为'id'
警告:语义问题:不兼容的指针类型将'CGSize*'(又名'struct CGSize*')传递给'id'类型的参数
错误:自动引用计数问题:ARC不允许将Objective-C指针隐式转换为"SEL"
警告:语义问题:不兼容的指针类型将'__unsafe_unretained Class'传递给'SEL'类型的参数
如果我查看方法的声明,它是:
OBJC_EXPORT void objc_msgSend_stret(id self, SEL op, ...)
__OSX_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);
Run Code Online (Sandbox Code Playgroud)
这与 …
struct objective-c objective-c-runtime class-method automatic-ref-counting
我有一个XCode 4.2项目,我一整天都在工作,很好,突然之间,在XCode崩溃后,我的项目开始编译并出现错误:
"file myClass.m: error: Lexical or Preprocessor Issue: 'map' file not found"
Run Code Online (Sandbox Code Playgroud)
myClass.m使用的位置:
#import <map>
#import <vector>
Run Code Online (Sandbox Code Playgroud)
我已经尝试了干净的构建,但xcode仍在抱怨.我怎样才能让它再次识别std:vector和std:map库?
我有一个没有文字的UIButton,有2个我想使用的图像(一个用于正常状态,另一个用于选择状态).图像小于按钮大小.
如何确保在绘制按钮时不缩放任何图像?设置imageView属性仅在正常状态下正确更改比例,而不是为选定状态更改比例.
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:imageNormal forState:UIControlStateNormal];
[button setImage:imageSelected forState:UIControlStateSelected];
// this shows the correct scale in normal mode but not when button is tapped
button.imageView.contentScaleFactor = 1.0;
button.imageView.contentMode = UIViewContentModeCenter;
Run Code Online (Sandbox Code Playgroud) 我有一个需要像UIButton一样运行的元素,但它同时可以看到几个(3)文本标签,并且在同一个边界框中有多个UIImages.它实际上是一个视图,有许多不同的其他UIViews和标签,需要看起来像一个按钮,但与标准UIButton相比,这些元素的定制位置更多.
从UIButton继承来完成这个更好还是UIControl是继承的?
当点击元素时,我确实想模仿所有高亮效果(如果它是UILabel,显示高亮文本颜色等).
我正在建立一个新的Web应用程序并决定是使用WSGI还是使用Django进行完整的框架路由.
该应用程序的首要要求:
1)应用程序没有任何UI,所有数据都通过带有JSON的REST api向客户端公开.
2)它将保留数据,因此MongoDB和可能亚马逊的SimpleDB将用于数据库端.
是否有理由使用Django或者我是否只能通过WSGI获得边际速度提升?
我构建的以前的服务器端应用程序在JVM上使用Java/Struts和Groovy/Grails.我的理解是Django是一个类似于Rails和Grails的MVC框架.
我还玩过Google App Engine,它使用WSGI作为代码上方的薄层来管理和路由请求.
我有一个UIImage(尺寸320x480),我希望用更小的UIImageView(尺寸:100x100)显示.
但是当我添加图像时,它会渗透UIImageView及其超级视图.如何限制图像的渲染,使其仅显示在UIImageView的边界内并相对于UIImageView的中心居中?
视图层次结构如下:
view: (main view associated with UIViewController)
-level_1 view (contentMode = UIViewContentModeScaleToFill)
--level_2 view (contentMode = UIViewContentModeCenter)
---level_3 view (container for UIImageView, contentMode = UIViewContentModeCenter)
-----UIImageView (contentMode = UIViewContentModeCenter)
Run Code Online (Sandbox Code Playgroud)
level_3视图大小:100x100图像大小:320x480
iphone ×8
ios ×5
ios5 ×4
objective-c ×3
class-method ×1
django ×1
django-wsgi ×1
python ×1
struct ×1
uiimageview ×1
uikit ×1
wsgi ×1
xcode4 ×1
xcode4.2 ×1