gpt4 book ai didi

c# - "Can' t 在 Xamarin Forms 项目中找到“NS*Types(例如 NSFileManager 或 NSUrl)

转载 作者:行者123 更新时间:2023-11-29 00:05:58 25 4
gpt4 key购买 nike

我在 Xamarin Forms 中遇到诸如 NSFileManager 和 NSUrl 之类的错误“未找到”。这些是我在我的类(class)中遇到这些错误的导入:

using System;
using System.IO;
using System.Reflection;
using DrinkUp.Controls;
using DrinkUp.iOS.Renderers;
using MediaPlayer;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

我正在使用的类位于 DrinkUp.iOS 中。无论何时何地我输入带有 NS 前缀的东西,它都会说找不到对象。有人可以告诉我我在这里做错了什么吗?

这是我的全类

using System;
using System.IO;
using System.Reflection;
using DrinkUp.Controls;
using DrinkUp.iOS.Renderers;
using MediaPlayer;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer(typeof(Video), typeof(VideoRenderer))]
namespace DrinkUp.iOS.Renderers
{
public class VideoRenderer : ViewRenderer<Video, UIView>
{
MPMoviePlayerController videoPlayer;
object notification = null;

void InitVideoPlayer()
{
var path = Path.Combine(NSBundle.MainBundle.BundlePath, Element.Source);

if (!NSFileManager.DefaultManager.FileExists(path)) {
Console.WriteLine("Video not exist");
videoPlayer = new MPMoviePlayerController();
videoPlayer.ControlStyle = MPMovieControlStyle.None;
videoPlayer.ScalingMode = MPMovieScalingMode.AspectFill;
videoPlayer.RepeatMode = MPMovieRepeatMode.One;
videoPlayer.View.BackgroundColor = UIColor.Clear;
SetNativeControl(videoPlayer.View);
return;
}

// Load the video from the app bundle.
NSUrl videoURL = new NUrl(path, false);

// Create and configure the movie player.
videoPlayer = new MPMoviePlayerController(videoURL);

videoPlayer.ControlStyle = MPMovieControlStyle.None;
videoPlayer.ScalingMode = MPMovieScalingMode.AspectFill;
videoPlayer.RepeatMode = Element.Loop ? MPMovieRepeatMode.One : MPMovieRepeatMode.None;
videoPlayer.View.BackgroundColor = UIColor.Clear;
foreach (UIView subView in videoPlayer.View.Subviews) {
subView.BackgroundColor = UIColor.Clear;
}

videoPlayer.PrepareToPlay();
SetNativeControl(videoPlayer.View);
}
}

最佳答案

第一个评论起作用了,我必须从 Foundation 获取 NS 类型。像 Foundation.NSUrl 等。这解决了我的问题。

关于c# - "Can' t 在 Xamarin Forms 项目中找到“NS*Types(例如 NSFileManager 或 NSUrl),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48069325/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com