假设我们有一个名为imageFile的自定义类,该类包含两个属性.
class imageFile {
var fileName = String()
var fileID = Int()
}
Run Code Online (Sandbox Code Playgroud)
很多都存储在Array中
var images : Array = []
var aImage = imageFile()
aImage.fileName = "image1.png"
aImage.fileID = 101
images.append(aImage)
aImage = imageFile()
aImage.fileName = "image1.png"
aImage.fileID = 202
images.append(aImage)
Run Code Online (Sandbox Code Playgroud)
问题是:如何通过'fileID'ASC或DESC对图像数组进行排序?
我刚刚开始看看Mattt奇妙的新Alamofire swift网络库,我不太确定如何将它与自定义标头一起使用.
我试图从AFNetworking转换为Alamofire的代码是这样的:
let request = NSMutableURLRequest(URL: url)
request.setValue(authorizationToken, forHTTPHeaderField:"Authorization")
Run Code Online (Sandbox Code Playgroud) 我正在尝试自己制作一个自定义alertView(适用于iOS7 +),但我在使用alertView演示文稿时遇到了困难.
我有一个黑色背景的UIViewController(alpha设置为0.25f),以及一个alertView作为子视图.
当我想显示alertView时,我以模态方式呈现viewController:
-(void) show
{
UIWindow* window = [[UIApplication sharedApplication] keyWindow];
self.modalTransitionStyle = UIModalPresentationCustom;
self.transitioningDelegate = self;
[window.rootViewController presentViewController:self animated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
这是我的动画师对象:
-(NSTimeInterval) transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext
{
NSLog(@"%s",__PRETTY_FUNCTION__);
return 2;
}
-(void) animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
NSLog(@"%s",__PRETTY_FUNCTION__);
UIView* toView = [transitionContext viewForKey:UITransitionContextToViewKey];
toView.alpha = 0;
UIView* container = [transitionContext containerView];
[container addSubview:toView];
[UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
toView.alpha = 0.5;
} completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
}];
}
Run Code Online (Sandbox Code Playgroud)
事情是:模态VC在背景中呈现VC呈现淡化,但是当动画结束时,呈现VC将从背景中移除.
如果我[transitionContext completeTransition:YES];改为调用,则呈现VC在后台但是在动画结束时删除了模态VC,所以如果我们发送'NO',我猜上下文取消了演示.
有没有办法将演示VC保留在后台而不必创建它的快照并将其设置为模态VC视图的背景?
我是一名学生,对编程很陌生.我想在业余时间学习Objective-C/Swift.我使用带有多个菜单/场景的swift的spriteKit制作了一个游戏.
我正试图从一个视图控制器转换到另一个视图控制器.为此,我使用了以下代码:
@IBAction func PlayButtonPressed(sender: AnyObject) {
let playStoryboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc : UIViewController = playStoryboard.instantiateViewControllerWithIdentifier("playGame") as UIViewController
self.presentViewController(vc, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
这适用于转换到新的VC场景,但是,我相信以前的VC仍然在堆栈中并占用内存,从而减慢了我的程序.
我已阅读其他一些帖子,您可以使用导航控制器删除VC.但是,我没有导航控制器; 只查看控制器.我已经看过一些关于removeFromParentViewController()和的 东西view.removeFromSuperview(),但我真的不知道如何实现它.除此之外,我没有找到我正在寻找的答案.
所以我要问的问题是如何从堆栈中删除以前的VC?任何帮助将是一个赞赏!(希望帮助很快,但Objective-C也有帮助)提前谢谢!
备注供参考:我相信Objective-C我的代码看起来像这样:
-(IBAction) PlayButtonPressed: (id) sender {
UIStoryboard *playStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [playStoryboard instantiateViewControllerWithIdentifier:@"playGame"];
[self presentViewController:vc animated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用我的Mac mini中的蓝牙开发应用程序.然而,在搜索全网后,我能找到的只是Apple的"蓝牙设备访问指南",而不是单个示例程序!
任何人都可以建议任何示例代码吗?
我想在我的程序中做什么:
我想通过PAN配置文件以编程方式将我的iPhone与我的Mac配对,然后以两种方式发送数据(流).我手动配对它,我成功地传输了数据.我只是想以编程方式做到这一点!
我想知道是否有办法setInterval明确自己.
像这样的东西:
setInterval(function () {
alert(1);
clearInterval(this);
}, 2000);
Run Code Online (Sandbox Code Playgroud)
我希望它继续检查,如果它完成它将停止.
在iOS 7中,我们将自定义动画转换为新的视图控制器,完成动画:
[self.animatedView removeFromSuperview]; //superview == self.view, in this case
[self presentViewController:newController animated:NO completion:nil];
Run Code Online (Sandbox Code Playgroud)
这在<= IOS 7中工作正常.我们也在使用dismissViewController:动画回原始时进行.但是,在iOS 8中,显示和关闭都会在动画结束和新视图外观之间显示一帧黑屏.有没有解决的办法?一切都已经在主线上发生了.
我正在为我的iPhone应用程序使用Facebook API,并有两个问题:
所有文档/示例似乎都将所有内容放在appDelegate中:实例化Facebook对象并在appDidFinishLaunching中进行授权,并覆盖应用程序:handleOpenURL方法.
在我的应用程序中,除非用户导航到特定视图并按下按钮,否则我不希望发生任何事情.我理解在该视图中,我将实例化Facebook对象并在按钮处理程序方法中启动授权,但是如何处理应用程序的覆盖:handleOpenURL?我必须使用与我的特定视图控制器中使用的不同的FB对象(在我的应用程序委托中实例化).
这种情况是否需要单身人士?或者它是一个很好的设计解决方案让我的appDelegate实例化FB对象,并通过我的程序中的任何其他地方访问它?
在FB文档中,它们告诉您覆盖应用程序:handleOpenURL方法:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [facebook handleOpenURL:url];
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
我有一个应用程序捕获kCVPixelFormatType_420YpCbCr8BiPlanarFullRange格式的实时视频来处理Y通道.根据Apple的文档:
kCVPixelFormatType_420YpCbCr8BiPlanarFullRange双平面分量Y'CbCr 8位4:2:0,全范围(亮度= [0,255]色度= [1,255]).baseAddr指向big-endian CVPlanarPixelBufferInfo_YCbCrBiPlanar结构.
我想在UIViewController中展示一些这些帧,是否有任何API可以转换为kCVPixelFormatType_32BGRA格式?您能给出一些提示来调整Apple提供的这种方法吗?
// Create a UIImage from sample buffer data
- (UIImage *) imageFromSampleBuffer:(CMSampleBufferRef) sampleBuffer {
// Get a CMSampleBuffer's Core Video image buffer for the media data
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
// Lock the base address of the pixel buffer
CVPixelBufferLockBaseAddress(imageBuffer, 0);
// Get the number of bytes per row for the pixel buffer
void *baseAddress = CVPixelBufferGetBaseAddress(imageBuffer);
// Get the number of bytes per row for the pixel buffer
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer); …Run Code Online (Sandbox Code Playgroud) 我试图将值传递给新的视图控制器 - 位于新的故事板文件中.但是当我这样做时,我从NewViewController得到的结果总是为零.
下面是我在新故事板中显示视图控制器的方法:
// Show create account page with custom transition
var storyboard : UIStoryboard = UIStoryboard(name: StoryboardName, bundle: nil)
var vc : UIViewController = storyboard.instantiateViewControllerWithIdentifier(NewViewController) as UIViewController
Run Code Online (Sandbox Code Playgroud)
我尝试在这里发送信息:
// Pass the delegate to the first view controller
let newViewController:NewViewController = NewViewController()
newViewController.createAccountDelegate = self
newViewController.teststring = "hello"
Run Code Online (Sandbox Code Playgroud)
然后呈现视图控制器.
vc.transitioningDelegate = self
vc.modalTransitionStyle = UIModalTransitionStyle.CoverVertical
self.presentViewController(vc, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
这是我的NewViewController,我尝试接收值.但最终仍然是零.
import UIKit
class NewViewController: UIViewController {
var createAccountDelegate:AccountCreationDelegate!
var teststring:NSString!
override func viewDidLoad() {
super.viewDidLoad()
}
Run Code Online (Sandbox Code Playgroud)
我错误地发送了这些值吗?
ios ×6
objective-c ×4
swift ×4
afnetworking ×1
alamofire ×1
arrays ×1
avfoundation ×1
bluetooth ×1
cocoa ×1
delegates ×1
facebook ×1
iobluetooth ×1
ios8 ×1
iphone ×1
javascript ×1
macos ×1
sorting ×1