小编chi*_*hah的帖子

在面向用户的方向上旋转GMSMarker

我要求在我当前的位置显示一个视图.如果设备旋转或位置将改变它将旋转.我研究很多,但得到所有代码,在某些位置有固定位置或角度但我没有固定位置.任何人都可以朝正确的方向开车.

我还使用了GMSMarker的旋转属性,但它不起作用.

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
    if (newHeading.headingAccuracy < 0){
        NSLog(@"heading accuracy < 0");
        return;
    }

    // Convert Degree to Radian and move the needle
    float oldRad =  (- manager.heading.trueHeading) * M_PI / 180.0f;
    float newRad =  (- newHeading.trueHeading) * M_PI / 180.0f;

    // Compass animation
    CABasicAnimation *theAnimation;
    theAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    theAnimation.fromValue = [NSNumber numberWithFloat:oldRad];
    theAnimation.toValue   = [NSNumber numberWithFloat:newRad];
    theAnimation.duration  = 0.5f;
    [source.layer addAnimation:theAnimation forKey:@"animateMyRotation"];

//    source.transform =  CGAffineTransformMakeRotation(newRad)
//    GMSMarker *source = [googleMap selectedMarker]; …
Run Code Online (Sandbox Code Playgroud)

objective-c google-maps-markers cllocationmanager ios gmsmapview

16
推荐指数
3
解决办法
1万
查看次数

当ios中的地区是"英国"时,如何获得系统时间格式?

我在ios中使用以下代码获取系统时间格式.当我目前的地区设置为"United State"时它工作正常,但是当我将该地区从"United State"改为"United Kingdom"时,它总是给出12小时的合成.

#pragma mark
#pragma mark - get system time
-(BOOL)getSystemTimeFormat
{
    NSString *strDateFormate = @"hh a";
    NSString *dateFormat = [NSDateFormatter dateFormatFromTemplate:strDateFormate options:0 locale:[NSLocale currentLocale]];
    if ([dateFormat rangeOfString:@"h"].location != NSNotFound)
    {
        [kNSUserDefaults setBool:YES forKey:@"TimeFormat"];
        [kNSUserDefaults synchronize];
        return YES;
    }
    else
    {
        [kNSUserDefaults setBool:NO forKey:@"TimeFormat"];
        [kNSUserDefaults synchronize];
        return NO;
    }

}
Run Code Online (Sandbox Code Playgroud)

"美国"地区的日志::

2015-01-27 11:32:16.090 [350:60b] 12 Formate :: 0
2015-01-27 11:32:16.585 [350:60b] Connect
2015-01-27 11:32:16.591 [350:60b ]位置更新...
2015-01-27 11:32:16.604 [350:60b]位置更新...
2015-01-27 11:32:16.622 [350:60b]位置更新...

"英国"地区的日志::

2015-01-27 11:33:35.785 [364:60b] 12 Formate …

iphone objective-c nsdateformatter date-formatting ios

14
推荐指数
1
解决办法
945
查看次数

UITableViewCell中的UICollectionView重用

我知道这个问题已经被问过很多遍了,但是没有一个解决方案会起作用。

我在uitableview单元格中有集合视图,并且在情节提要中准备了表格视图和集合视图的单元格,我的问题是假设我滚动了单元格1集合视图,然后单元格4集合也自动滚动到了该位置。我如何处理这种情况。

请注意,现在我对屏幕进行静态设计

我的密码

// MARK:
    // MARK: table view delegate method

    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }
    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {

        if Appconstant.isIpad()
        {
            return 215.0
        }
        return 185.0

    }
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 6
    }
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let strCell = "WorkoutCell" //+ "\(indexPath.row)"
        let cell = tableView.dequeueReusableCellWithIdentifier(strCell) as? WorkoutCell
//        if cell == nil
//        {
// …
Run Code Online (Sandbox Code Playgroud)

uitableview ios uicollectionview swift

8
推荐指数
1
解决办法
1087
查看次数

为什么 RealityKit 内存在 deinit 调用后没有清除?

我无法从内存中释放我的 RealityKit ARView()。不幸的是,我知道 ARKit + SceneKit 也存在类似的问题,但解决方法并不能解决我的问题。

上述解决方案通过手动删除所有“可疑”内容来发挥作用。这正是我在更广泛的范围内所做的:

func closeCurrentView(completion: (() -> Void)? = nil, isScanAnotherFloor: Bool = false) {
    if backgroundRenderingID != UIBackgroundTaskIdentifier.invalid {
        let app = UIApplication.shared
        app.endBackgroundTask(self.backgroundRenderingID)
        self.backgroundRenderingID = UIBackgroundTaskIdentifier.invalid
    }
    self.arView?.session.pause()
    self.arView?.session.delegate = nil
    self.arView?.scene.anchors.removeAll()
    self.arView?.removeFromSuperview()
    self.arView?.window?.resignKey()
    self.arView = nil
}
Run Code Online (Sandbox Code Playgroud)

内存会上升到90MB到250MB,一旦deinit调用就会减少到175MB,不会清除所有内存。

另外在初始化时,我也设置了适当的选项。

arView?.renderOptions = [
    .disableMotionBlur,
    .disableDepthOfField,
    .disablePersonOcclusion,
    .disableGroundingShadows,
    .disableFaceOcclusions,
    .disableHDR
]
Run Code Online (Sandbox Code Playgroud)

但仍然没有运气。

在此输入图像描述

swift arkit realitykit

8
推荐指数
1
解决办法
892
查看次数

如何在用户终止应用程序时停止播放MPMusicPlayerController?

我的申请中有以下情况:

我的应用程序中有一个音乐系统,我曾经MPMusicPlayerController播放音乐; 到目前为止,每件事情都很好.

我的问题:当用户开始在我的应用程序中播放音乐时,一段时间后终止,音乐无法停止,因为我正在使用该[MPMusicPlayerController systemMusicPlayer]对象.我知道还有另外一种选择applicationMusicPlayer,但它停止在后台播放音乐,这不符合我的要求.

当用户终止应用程序时,如何停止播放音乐?

我有一些代码试图阻止它,applicationWillTerminate:但它只适用于某些情况:

  1. 如果我按两次主页按钮并从多任务UI终止应用程序,则应用程序可以停止音乐播放器.

  2. 如果我按下主页按钮一次然后转到主屏幕,之后我按两次主页按钮并终止应用程序然后它无法停止我的音乐播放器.

我试图applicationWillTerminate:在第二个例子(从上面)中设置一个断点,应用程序崩溃并且没有执行我的代码,这与第一种情况不同.

UPDAT

我知道当我使用MPMusicPlayerController后台模式时不需要它,因为它在本机音乐播放器中启动音乐.

任何帮助,将不胜感激.

objective-c mpmusicplayercontroller ios

7
推荐指数
1
解决办法
1175
查看次数

Imagepicker叠加层不会仅在ios 10中全屏显示

我正在使用Imagepicker叠加来捕捉照片.在iOS 9中,我的代码工作正常,但是当我在iOS 10上运行我的代码时,它在底部显示了一个空间,而这个空间在iOS 9上没有显示.我试图解决它,但我无法做到.

这是我生成问题的代码:

- (void)openCamerawithOption :(UIImagePickerControllerCameraCaptureMode)camType
{
    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {

        [[NSOperationQueue mainQueue] addOperation:[NSBlockOperation blockOperationWithBlock:^{
            [self createImagePicker:camType];
        }]];
    }
}

-(void)createImagePicker :(UIImagePickerControllerCameraCaptureMode)camType
{
    if (!imagePickerController) {
        imagePickerController = [[NonRotatableImagePickerController alloc] init];
    }
    //[imagePickerController.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height+(iOS7?0:20.0))];
    [APPSINGLETON setBorder:imagePickerController.view color:[UIColor redColor]];

    imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
    imagePickerController.delegate = self;
    imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
    imagePickerController.allowsEditing = YES;
    imagePickerController.videoMaximumDuration = 60.0;

    if (iOS7) {
        CGSize screenBounds = APPDELEGATE.screenSize;
        CGFloat cameraAspectRatio = 4.0f/3.0f;
        CGFloat camViewHeight = screenBounds.width * cameraAspectRatio;
        CGFloat scale = screenBounds.height / camViewHeight; …
Run Code Online (Sandbox Code Playgroud)

objective-c ios ios10

7
推荐指数
1
解决办法
595
查看次数

强迫方向改变有时不起作用

在我的应用程序中按下某个按钮时,视图应该从纵向更改为横向.当用户返回时,视图控制器应该更改回肖像.但有时方向不会改变或使用错误的视图框架.

这是我的代码

-(void)btnSignClicked:(CustomSignButton *)btn {
    isSignButtonClicked = true;
    if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_0) {
        NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
        [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
    }
    else
    {
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES];
    }
    selectedWaiverId = btn.customTag;

    SignatureView *obj = [[SignatureView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) delegate:self]; // Most of time got size (568,320) but some time i got (320,568), Don't know why
    [self.view addSubview:obj];
}

#pragma mark - SIGNATUREVIEW DELEGATE
-(void)removeSignatureView:(SignatureView *)signatureView {
    isSignButtonClicked = false;

    if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_0)
    {
        NSNumber *value …
Run Code Online (Sandbox Code Playgroud)

objective-c uiinterfaceorientation ios ios8

6
推荐指数
1
解决办法
1006
查看次数

App Invites已弃用

我正在开发一个具有appinvite功能的应用程序,但在pod更新后我得到低于下面的错误

'show(from:with:delegate :)'已弃用:App Invites不再受支持

之后我转到脸书开发者网站,发现下面的文字在上面

随着Facebook SDK版本4.28.0的发布,App Invites已被弃用.它将被支持到2018年2月5日.(链接)

在应用程序邀请停止支持ios中的非游戏应用程序后,有没有其他方式在Facebook上邀请?

facebook ios facebook-app-invites

6
推荐指数
1
解决办法
948
查看次数

当屏幕快速关闭时,IOS Audio停止播放

嗨,我是IOS和Swift的新手.

我正在制作一个包含两个音频文件的应用程序,它们在第二个播放ViewController.我使用导航控制器,然后push转到第二个ViewController.正如我在回到第一个时发现的那样ViewController,音频不会停止,我使用了这段代码:

override func viewWillDisappear(animated: Bool) {
    audioPlaying.stop()
}
Run Code Online (Sandbox Code Playgroud)

现在音频在返回时停止,但是如果屏幕熄灭,音频将停止意味着当应用程序被锁定或在后台时,我怎么能摆脱这个?

更多代码:

var audioPlaying = AVAudioPlayer()

override func viewDidLoad() {
    super.viewDidLoad()
    audioPlaying = AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("audioOne", ofType: "mp3")!), error: nil)
}

override func viewWillDisappear(animated: Bool) {
        audioPlaying.stop()
}
@IBAction func playPause(sender: AnyObject) {
    if buttonLabelChange == true {
        let image = UIImage(named: "btn_pause.png") as UIImage?
        playPauseButton.setBackgroundImage(image, forState: UIControlState.Normal)
        buttonLabelChange = false
        audioPlaying.play()
    }else{
        let image = UIImage(named: "btn_play.png") as UIImage?
        playPauseButton.setBackgroundImage(image, forState: UIControlState.Normal) …
Run Code Online (Sandbox Code Playgroud)

iphone avaudioplayer ios swift

5
推荐指数
1
解决办法
962
查看次数

如何在所有设备中使用swift4在CollectionView中显示两列

在此输入图像描述

要在collectionView中只显示两列,我正在使用这段代码

    let layout = self.collectionView.collectionViewLayout as! UICollectionViewFlowLayout
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0)
    layout.minimumInteritemSpacing = 4
    layout.itemSize = CGSize(width:(self.collectionView.frame.size.width - 10)/2,height: (self.collectionView.frame.size.height)/3)
Run Code Online (Sandbox Code Playgroud)

但它只能在5s上正常显示,而不是在每个iphone上显示.请帮忙.

我想像这个图像一样显示我的视图控制器.请帮助任何人

在此输入图像描述

ios uicollectionview swift swift4

5
推荐指数
3
解决办法
6018
查看次数