如何在一部分中设置单元格间距UICollectionView?我知道有一个属性minimumInteritemSpacing我已经设置为5.0仍然间距不出现5.0.我已经实现了flowout委托方法.
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
return 5.0;
}
Run Code Online (Sandbox Code Playgroud)
我仍然没有得到理想的结果.我认为它的最小间距.我有没有办法设置最大间距?

我有一个视图出现在其父视图肖像模式的中心,我应该使用什么autoresizemask,以便它也以横向模式显示在中心.它的大小应该保持不变.我只是希望它的原点应该在这一点自动移动,以便它出现在中心.有什么帮助吗?
我给了
[parentView setAutoResizesSubview:YES];
parentView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
Run Code Online (Sandbox Code Playgroud) 我有一个协议,Address它继承自另一个协议Validator,并Address满足Validator扩展中的要求.
还有另一个协议,FromRepresentable它有一个associatedType(ValueWrapper)要求Validator.
现在,如果我尝试使用Addressas associatedType,那么它不会编译.它说,
推断类型'Address'(通过匹配要求'valueForDetail')无效:不符合'Validator'.
这种用法是非法的吗?我们是不是应该能够使用Address的地方Validator,因为所有Addresses都是Validator.
下面是我正在尝试的一段代码.
enum ValidationResult {
case Success
case Failure(String)
}
protocol Validator {
func validate() -> ValidationResult
}
//Address inherits Validator
protocol Address: Validator {
var addressLine1: String {get set}
var city: String {get set}
var country: String {get set}
}
////Fulfill Validator protocol requirements in extension
extension …Run Code Online (Sandbox Code Playgroud) 许多论坛都讨论过这个话题,但我仍然无法完全理解其performBlockAndWait实际效果如何.根据我的理解,context.performBlockAndWait(block: () -> Void)将在阻塞调用程序线程的同时在其自己的队列中执行该块. 文档说:
您将"标准"消息分组以发送到块中的上下文以传递给这些方法之一.
什么是"标准"消息?它还说:
基于队列的托管对象上下文的Setter方法是线程安全的.您可以直接在任何线程上调用这些方法.
这是否意味着我可以设置托管对象的属性,该对象是在performBlock*API之外的上下文的performBlockAPI中获取的?
根据我的理解,调用performBlockAndWait(block: () -> Void)具有并发类型的上下文.MainQueueConcurrencyType将在从主线程调用时创建死锁并永久阻止UI.但在我的测试中,它并没有造成任何僵局.
我认为它应该创建死锁的原因是,performBlockAndWait将首先阻塞调用程序线程,然后在其自己的线程上执行该块.由于上下文必须执行其块的线程与已被阻塞的调用者线程相同,因此它将永远无法执行其块并且线程将永远被阻塞.
但是我在一些奇怪的场景中遇到了僵局.我有以下测试代码:
@IBAction func fetchAllStudentsOfDepartment(sender: AnyObject) {
let entity = NSEntityDescription.entityForName("Department", inManagedObjectContext: privateContext)
let request = NSFetchRequest()
request.entity = entity
request.relationshipKeyPathsForPrefetching = ["students"]
var department: Department?
privateContext.performBlockAndWait { () -> Void in
department = try! self.privateContext.executeFetchRequest(request).first as? Department
print(department?.name)
guard let students = department?.students?.allObjects as? [Student] else {
return
}
for student in students …Run Code Online (Sandbox Code Playgroud) 我可以使用XMPPFramework创建一个MUC,并使用下面的代码发送用户邀请请求加入该房间.
// Creating
AppDelegate *dele =(AppDelegate *) [[UIApplication sharedApplication]delegate];
xmppRoom = [[XMPPRoom alloc] initWithRoomStorage:dele jid:[XMPPJID jidWithString:self.roomName] dispatchQueue:dispatch_get_main_queue()];
[xmppRoom addDelegate:dele delegateQueue:dispatch_get_main_queue()];
[xmppRoom activate:dele.xmppStream];
[xmppRoom joinRoomUsingNickname:self.myNick history:nil];
// Inviting
[xmppRoom inviteUser:[XMPPJID jidWithString:@"abc@host"] withMessage:@"Come Join me"];
Run Code Online (Sandbox Code Playgroud)
用户"abc"如何知道他已收到邀请,他如何通过接受或拒绝对此做出反应?
我在XMPPFramework中找不到任何直接处理聊天室邀请的课程.我的研究表明,每当用户收到聊天室邀请时,都会调用xmmppStream的委托方法:
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
Run Code Online (Sandbox Code Playgroud)
在该消息中,我检查它是否包含名为"invite"的NSXMLElement,如果它包含,则我向用户发送回调.然后我创建聊天室,其名称与用户收到邀请的聊天室名称相同,并进入新创建的房间.它工作正常,但安静冗长,不安静有效.我想知道是否有可用XMPPFramework一类在这里它可以单独处理的聊天室邀请.例如,检测,接受和拒绝房间邀请.
我提取房间名称的代码:
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
{
NSXMLElement * x = [message elementForName:@"x" xmlns:XMPPMUCUserNamespace];
NSXMLElement * invite = [x elementForName:@"invite"];
NSXMLElement * decline = [x elementForName:@"decline"];
NSXMLElement * directInvite = [message elementForName:@"x" xmlns:@"jabber:x:conference"];
NSString *msg = [[message …Run Code Online (Sandbox Code Playgroud) 我的tableview中有56个部分,我正在存储当前在名为"activeTimeSlot"的整数变量中选择的部分编号.如何使用以下方法重新加载当前选定的部分.我这样做
[self.tblView reloadSections:[NSIndexSet indexSetWithIndex:activeTimeSlot] withRowAnimation:UITableViewRowAnimationAutomatic];
Run Code Online (Sandbox Code Playgroud)
但我观察到这样做是为所有部分调用tableview的下面数据源方法,即重新加载所有部分.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
Run Code Online (Sandbox Code Playgroud)
我不知道如何使用NSIndexSet以及如何使用NSIndexSet重新加载超过1个部分.
我有一个分页的滚动视图.在viewDidLoad中,我检查当前方向是否为横向,然后我设置其内容大小的高度440
if (UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation]))
{
[scroll setContentSize:CGSizeMake(self.scroll.frame.size.width*numberOfPages,340)];
}
else if (UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation]))
{
[scroll setFrame:CGRectMake(0,0,480,480)];
[scroll setContentSize:CGSizeMake(self.scroll.frame.size.width*numberOfPages, 440)];
}
Run Code Online (Sandbox Code Playgroud)
一切正常滚动视图滚动顺畅,没有对角线滚动.
但是当方向改变时
我必须再次设置scrollview的框架和内容,我将其设置如下
-(void)orientationChanged:(id)object
{
if(UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation]))
{
self.scroll.frame = [[UIScreen mainScreen]bounds];
[scroll setContentSize:CGSizeMake(self.scroll.frame.size.width*numberOfPages, 340)];
}
else
{
self.scroll.frame = CGRectMake(0,0,480,480);
[scroll setContentSize:CGSizeMake(self.scroll.frame.size.width*numberOfPages, 600)];
}
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么我必须在横向模式下将内容大小的高度设置为600,这太不够了.并且它增加了另一个问题,即scrollview开始对角线滚动,我不想要,因为它看起来很奇怪.任何人都可以帮我理解我错过的地方和地点吗?
我已将scrollview的自动调整遮罩设置为
[scroll setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleHeight];
Run Code Online (Sandbox Code Playgroud)
但改变它没有帮助.
objective-c uiscrollview uiinterfaceorientation ios contentsize
是否有任何方法可以将旋转视图的变换传递给其子视图?我有一个自定义MKAnnotationView,我根据用户的标题值旋转.在自定义Annotation视图类的下面的方法中,我将一个子视图添加到注释视图.
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
if(selected)
{
[self addSubview:self.myCallOutView];
return;
}
[self.myCallOutView removeFromSuperview];
}
Run Code Online (Sandbox Code Playgroud)
但问题是当我的注释视图旋转然后我选择任何注释时,myCallOutView也出现旋转,我不想要.我正在使用下面的线旋转自定义注释视图
[self setTransform:CGAffineTransformMakeRotation(angle * M_PI / -180.0)];
Run Code Online (Sandbox Code Playgroud)
我该如何避免这种情况?在将myCallOutView添加为子视图之前,是否需要对myCallOutView应用一些转换?
有没有什么方法可以根据UISlider的值旋转图像?我知道使用Gestures可以轻松执行旋转,但我必须使用UISLider执行它.
我希望在我的应用程序中收到任何键盘事件的通知,applitionDidFinishLaunching方法中的以下代码在狮子身上运行良好,但它没有在山狮上调用.
[NSEvent addGlobalMonitorForEventsMatchingMask:NSKeyDownMask handler:^(NSEvent *event) {
NSLog(@"key pressed");
}];
Run Code Online (Sandbox Code Playgroud)
我正在获取鼠标移动事件但不适用于键盘事件.
ios ×9
objective-c ×6
swift ×2
contentsize ×1
core-data ×1
macos ×1
mkannotation ×1
mkmapview ×1
nsevent ×1
uiimageview ×1
uiscrollview ×1
uitableview ×1
uiview ×1
xmpp ×1