我在Swift 2.3中这样做的方式是:
let currentDate = NSDate()
let currentCalendar = NSCalendar.currentCalendar()
var startDate : NSDate?
var endDate : NSDate?
// The following two lines set the `startDate` and `endDate` to the start of the day
currentCalendar.rangeOfUnit(.Day, startDate: &startDate, interval: nil, forDate: currentDate)
currentCalendar.rangeOfUnit(.Day, startDate: &endDate, interval: nil, forDate: self)
let intervalComps = currentCalendar.components([.Day], fromDate: startDate!, toDate: endDate!, options: [])
print(intervalComps.day)
Run Code Online (Sandbox Code Playgroud)
现在这已经全部改变了Swift 3.我必须使用NSCalendar和NSDate不断地输入as,或者找到Swift 3的方式.
在Swift 3中使用它的正确方法是什么?
其他一些人已经提出了这个问题,但它从来没有被回答过.问题似乎微不足道,但Apple的文档或其他地方尚未解决.
我正在使用以下showInView方法呈现我的UIActionSheet实例:
UIActionSheet *myActionSheet = [[UIActionSheet alloc] initWithTitle:@"Test" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Destroy" otherButtonTitles:@"One", @"Two", nil];
[myActionSheet showInView:self.view];
Run Code Online (Sandbox Code Playgroud)
UIActionSheet在中心以任何方向呈现,但是当我旋转iPad时,它会在top-right或中看到bottom-left(取决于方向是否更改为纵向或横向).
如果将自动调整大小设置为UIViewAutoresizingFlexibleBottomMargin和UIViewAutoresizingFlexibleRightMargin,这是大多数视图元素的默认autoresizingMask值,则会出现这种情况,因此我尝试通过调用setAutoresizingMaskUIActionSheet实例上的方法来重置该值.
[myActionSheet setAutoresizingMask:UIViewAutoresizingNone];
Run Code Online (Sandbox Code Playgroud)
但是,Autoresizing Mask的这个或任何其他价值都无法实现任何改变.
有没有解决这个问题的方法?我宁愿不诉诸于解雇UIActionSheet轮换并重新展示它 - 原则上这种方法似乎是不必要的.
我正在尝试使用连接到的简单PHP工具向我的手机发送推送通知ssl://gateway.push.apple.com:2195,但连接失败并出现以下错误:
Warning: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in <Users/.../file.php> on line 30
Warning: stream_socket_client(): Failed to enable crypto in <Users/.../file.php> on line 30
Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in <Users/.../file.php> on line 30
Failed to connect: 0
Run Code Online (Sandbox Code Playgroud)
这一切都始于我升级到macOS Sierra的GM种子.macOS Sierra有哪些新功能会影响SSL连接?我该如何解决这个问题?
我想使用Interface Builder设计一个UIView和一些子视图(UIWebView,UIToolbar,一些UIBarButtonItems,一个进度指示器等等),但我认为传统上不需要使用UIViewController,presentViewController:animated等等
所以,我创建了一个自定义类, .h文件代码如下:
@interface FileInteractionManager : NSObject {
}
@property (nonatomic, retain) IBOutlet UIView *fileView;
@property (nonatomic, retain) IBOutlet UIWebView *fileWebView;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *printButton;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *optionsButton;
@property (nonatomic, retain) IBOutlet UIBarButtonItem *doneButton;
Run Code Online (Sandbox Code Playgroud)
我的.m文件如下:
@implementation FileInteractionManager
@synthesize fileView, fileWebView, doneButton, optionsButton, printButton;
-(id)init {
NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"FileInteractionView" owner:self options:nil];
NSLog(@"Load success!");
return self;
}
Run Code Online (Sandbox Code Playgroud)
最后,我创建了一个名为"FileInteractionView.xib"的独立xib文件,将文件的所有者更改为我在上面创建的自定义类,并连接IBOutlets.
当我init在我的类上调用该方法时,我可以在调试器中看到我的所有IBOutlet对象都已正确实例化.
我的问题是:
该loadNibNamed:owner:options:方法是加载我的独立.xib文件的正确方法吗?我不喜欢这个方法返回一个我没用的数组(返回的顶级对象匹配我的变量fileView,但我已经通过Interface Builder链接它们).
我的一般方法是否正确解决我的问题?我执行了上面的步骤,因为我想要一个简单的UIView …
可能重复:
iOS SDK:通过代码UIImageView 将按钮移动到屏幕中心
.缩放和居中到任意矩形.无法在屏幕上确定正确的中心
我正在尝试将UIActivityIndicator集中在UIWebView中(它又是UIScrollView的子视图,左侧还有一个UIToolbar元素 - 尽管左侧工具栏并不总是可见)
之前已经提出过类似的问题,但重点是"动态地"找到中心,即改变方向以及左侧工具栏的存在与否.
什么是最好的方法?有没有比覆盖方法更好的方法shouldAutorotateToInterfaceOrientation呢?
iphone xcode screen-orientation uiactivityindicatorview ipad
我是Xcode开发的新手,我想在我的iPhone应用程序中开发一个slide-up menu触发器UIToolbar.
我正在看的是创建一个带有菜单按钮的子视图,将其添加到主视图,并在toggle点击按钮时向上滑动(可见)或向下(隐藏).
我该如何以编程方式执行此操作?!适用于iPhone 的Opera应用程序做得很好(见图).

xcode ×3
iphone ×2
apns-php ×1
autorotate ×1
ios ×1
ios5 ×1
ipad ×1
macos-sierra ×1
nscalendar ×1
nsdate ×1
objective-c ×1
swift3 ×1
uiview ×1
xib ×1