我有一个CALayer,我想添加一个可伸缩的图像.如果我这样做:
_layer.contents = (id)[[UIImage imageNamed:@"grayTrim.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0.0, 15.0, 0.0, 15.0)].CGImage;
Run Code Online (Sandbox Code Playgroud)
它不起作用,因为图层的默认contentGravity是kCAGravityResize.
我已经读过这可以使用contentsCenter完成,但我似乎无法弄清楚我将如何使用它来实现我的CALayer中的拉伸图像.
欢迎任何想法!
霍拉丘
嗨,我有一个应用程序,我有两个*.pngs默认闪屏:
Default-Landscape.png Default-Portrait.png
我想要的是在我的应用程序加载并准备好时,将此默认启动画面设置为动画.
为了达到这个目的,我通常会使用默认横向或默认纵向(取决于设备方向)呈现UIImageView,将其保留在屏幕上一段时间,然后将其设置为动画.
我的问题是,如果我呼吁[[UIDevice currentDevice] orientation]在
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
Run Code Online (Sandbox Code Playgroud)
答案始终是设备处于纵向方向,即使我清楚地将其置于风景中.我在模拟器和设备上尝试了这个,行为是一样的.
有没有人知道这个或其他方法的解决方案?
谢谢!
iphone uikit uidevice uiinterfaceorientation device-orientation
我正试图让UITextField看起来像iPad上的safari应用程序中提供的谷歌搜索字段.该字段的目的是相同的(搜索框).
我知道我可以使用UISearchBar,但我必须使用hackish代码来摆脱放大镜图标和背景,我不希望这样.
我正在使用Apple使用的TextField作为搜索框附加图像.如何修改UITextField以使其外观和行为类似于此屏幕截图中的搜索字段?

我试图修改UITextField的图层roundedCorners属性,但这不能按预期工作.
很感谢任何形式的帮助!
谢谢!
问题是这样的:
我需要能够在具有大量表视图的大型现有应用程序中获取 didSelectRowAtIndexPath 的分析。
我的第一个想法是在 didSelectRowAtIndexPath: 上进行方法调整:但是我的应用程序崩溃并显示“无法识别的选择器发送到实例”消息,具体取决于原始 didSelectRowAtIndexPath 实现中访问的内容。
以下是我尝试在 UIViewController 类别中实现此目的的方法:
#import "UIViewController+Swizzle.h"
@implementation UIViewController (Swizzle)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPathSwizzled:(NSIndexPath *)indexPath {
NSLog(@"Log something here");
[self tableView:tableView didSelectRowAtIndexPathSwizzled:indexPath];
}
+ (void) initialize {
BOOL conformsToTableViewDelegate = class_conformsToProtocol(self, @protocol(UITableViewDelegate));
if(conformsToTableViewDelegate) {
Method method1 = class_getInstanceMethod(self, @selector(tableView:didSelectRowAtIndexPath:));
Method method2 = class_getInstanceMethod(self, @selector(tableView:didSelectRowAtIndexPathSwizzled:));
method_exchangeImplementations(method1, method2);
}
}
@end
Run Code Online (Sandbox Code Playgroud)
这能实现吗?如果是这样,我做错了什么?
谢谢!
我有一个全屏图片库,使用UICollectionView。它已分页,并且一切运行正常,但是有一件事我不喜欢。
单元格只有在它们进入可见视口时才可以重用,并且在分配新图像时(对于当前行为而言是正常的),我会获得闪烁效果。
如何指定比当前UICollectionView框架稍大的视口,以便加载和重用视图外的+ 1 / -1页面?当它们进入视线时,它们已经被初始化并可以使用了,因此闪烁效果将消失。
谢谢!
嗨,我在ARC下有一个令人讨厌的内存管理问题,无法弄清楚如何解决它.问题就像这样,我有这些对象:
ObjectManager - 对核心数据执行fetchRequests并获取一个或多个NSManagedObjects的单例
UIViewControllerA - 一个视图控制器,其中有一个按钮"PassManagedObject"和一个声明如下的属性:
@property (strong, nonatomic) ManagedObject *objectForToday;
Run Code Online (Sandbox Code Playgroud)
在UIViewControllerA上的viewDidLoad中,我调用了方法refreshDailyObject,它执行此操作:
self.objectForToday = nil;
self.objectForToday = [[ObjectManager sharedManager] getDailyObject];
Run Code Online (Sandbox Code Playgroud)
如果我挖掘的PassManagedObject按钮I 创建UIViewControllerB,通过所述objectForToday它和显示它,见下文
- (IBAction)passManagedObjectTapped:(id)sender {
UIViewControllerB *viewController = [[UIViewControllerB alloc] initWithNibName:@"UIViewControllerB"];
viewController.object = self.objectForToday;
[self.navigationController pushViewController:viewController animated:NO];
}
Run Code Online (Sandbox Code Playgroud)
UIViewControllerB有一个声明如下的属性:
@property (strong, nonatomic) ManagedObject *object;
Run Code Online (Sandbox Code Playgroud)
和一个按钮" 后退 ",它执行此操作:
- (IBAction)backAction:(id)sender {
self.object = nil;
[self.navigationController popViewControllerAnimated:NO];
}
Run Code Online (Sandbox Code Playgroud)
现在的问题是这个.如果我点击不断passManagedObjectTapped然后backAction,并再次passManagedObjectTapped又一次backAction,然后再passManagedObjectTapped和自动化这个我得到最终收到内存警告1,然后崩溃. …
memory-management core-data objective-c ios automatic-ref-counting
嗨,我有一个这样的枚举:
typedef enum {
Top,
Bottom,
Center
} UIItemAlignment;
Run Code Online (Sandbox Code Playgroud)
在我的代码中,我试着像这样使用它:
item.alignment = UIItemAlignment.Top;
Run Code Online (Sandbox Code Playgroud)
我收到这样的错误:"'UIItemAlignment'之前的预期表达式"
如果我只使用:
item.alignment = Top;
Run Code Online (Sandbox Code Playgroud)
一切正常,但如果我尝试以其他方式使用它,为什么会出现此错误?
_alignment是一个NSInteger,它有一个像这样声明的属性
@property (readwrite) NSInteger alignment; 我在我的实现文件中合成了它.
所以我的问题是,为什么我会收到此错误?
通常块可以有3种类型:NSGlobalBlock,NSStackBlock,NSMallocBlock.让我们举个例子:
void (^aBlock)(NSString *someString) = ^(NSString *someString){
NSLog(@"Block was executed. %@", someString);
};
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:aBlock forKey:@"aBlock"];
Run Code Online (Sandbox Code Playgroud)
由于ABLOCK不捕获周围的范围,如果我做PO字典,我得到
aBlock = < NSGlobalBlock:0x165dde60>这是正确的
如果我那么做:
NSString *string = @"Test";
void (^aBlock)(NSString *someString) = ^(NSString *someString){
NSLog(@"Block was executed. %@ %@", someString, string);
};
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:aBlock forKey:@"aBlock"];
Run Code Online (Sandbox Code Playgroud)
然后po字典,我得到:
aBlock = < NSMallocBlock:0x165dde60> 这就是我的困惑
这不应该是一个NSStackBlock,只有当我这样做时才成为NSMallocBlock:
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:[aBlock copy] forKey:@"aBlock"];
Run Code Online (Sandbox Code Playgroud)
我使用ARC在iOS 7.1上,据我所知,在向下传递堆栈时,不应该在ARC中默认复制块,并且只有在向上传递堆栈(从函数返回)时才应复制它们.
我在这里错过了什么?
memory-management objective-c nsdictionary objective-c-blocks automatic-ref-counting
我试图在macOS 10.13中宣传具有Multipeer Connectivity的服务:
override init() {
self.serviceAdvertiser = MCNearbyServiceAdvertiser(peer: peerID, discoveryInfo: nil, serviceType: serviceID);
super.init();
self.serviceAdvertiser.delegate = self;
self.serviceAdvertiser.startAdvertisingPeer();
}
Run Code Online (Sandbox Code Playgroud)
哪里
private let serviceID = "sample-test";
private let peerID = MCPeerID(displayName: Host.current().localizedName!);
Run Code Online (Sandbox Code Playgroud)
调用广告客户端的调用方法会立即失败,而不是让正确的委托回调方法失败,这就是我在控制台中获得的内容:
2017-10-16 11:22:35.568607-0700 macApp[3060:288948] [] tcp_listener_socket_create bind(fd 3) failed: [1] Operation not permitted
2017-10-16 11:22:35.569223-0700 macApp[3060:288940] [MCNearbyServiceAdvertiser] Server did not publish: errorDict [{
NSNetServicesErrorCode = 1;
NSNetServicesErrorDomain = 1;
}].
Run Code Online (Sandbox Code Playgroud)
不知道怎么解决这个问题?
更新:
在iOS模拟器中运行完全相同的代码工作正常,所以我猜它与Mac机器上的某些权限有关.
看到日志显示这是一个权限问题,我继续在Mac上启用root用户,并尝试运行相同的代码无济于事.
我正在考虑关闭系统完整性保护,但我很难接受Apple如果要使用所有这些安全性妥协而发布此框架的事实.会继续调查.
@protocol MyViewDelegate <NSObject>
- (void) didFinishProcessing:(MyView*)myView; //compiler stops here with error
@end
@interface MyView : MySuperclass {
id<MyViewDelegate> _delegate;
}
@property (nonatomic, retain) id<MyViewDelegate> delegate;
@end
Run Code Online (Sandbox Code Playgroud)
当我尝试编译时,我会在MyView之前得到" 预期的").错误在哪里?
objective-c ×5
ios ×3
iphone ×3
ios5 ×2
uikit ×2
bonjour ×1
c ×1
calayer ×1
core-data ×1
enums ×1
nsdictionary ×1
protocols ×1
quartz-core ×1
swift ×1
swizzling ×1
typedef ×1
uidevice ×1
uiimage ×1
uiscrollview ×1
uisearchbar ×1
uitableview ×1
uitextfield ×1