我想问一下简单的麦克风音量检测问题.我的代码适用于iOS 6或更低版本,但不适用于iOS 7,我的代码如下所示:
-(void)viewDidLoad{
NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat: 44100.0], AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
[NSNumber numberWithInt: AVAudioQualityMax], AVEncoderAudioQualityKey,
nil];
NSError *error;
recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];
if (recorder) {
[recorder prepareToRecord];
recorder.meteringEnabled = YES;
[recorder record];
} else{
NSLog([error description]);
}
}
// then call periodically with the following method, volumeLevelSampling
-(void)volumeLevelSampling{
[recorder updateMeters];
NSLog(@"Average input: %f Peak input: %f", [recorder averagePowerForChannel:0], [recorder peakPowerForChannel:0]);
}
Run Code Online (Sandbox Code Playgroud)
它在iOS 6中运行得非常好,但它在iOS 7中没有采样任何东西.结果总是-120.
我想用相机录制时播放音频文件.我使用AVAudioPlayer播放音频和AVCamCaptureManager进行录制.
但是当音频开始播放时,预览屏幕就会冻结.我该怎么办?
谢谢你的帮助.这是代码.(我正在研究AVCam的例子.)
这是预览部分.
if ([self captureManager] == nil) {
AVCamCaptureManager *manager = [[AVCamCaptureManager alloc] init];
[self setCaptureManager:manager];
[[self captureManager] setDelegate:self];
if ([[self captureManager] setupSession]) {
AVCaptureVideoPreviewLayer *newCaptureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:[[self captureManager] session]];
UIView *view = [self videoPreviewView];
CALayer *viewLayer = [view layer];
[viewLayer setMasksToBounds:YES];
CGRect bounds = CGRectMake(0, 0, 480, 320);
[newCaptureVideoPreviewLayer setFrame:bounds];
if ([newCaptureVideoPreviewLayer isOrientationSupported]) {
[newCaptureVideoPreviewLayer setOrientation:[DeviceProperties setPreviewOrientation]];
}
[newCaptureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
[viewLayer insertSublayer:newCaptureVideoPreviewLayer below:[[viewLayer sublayers] objectAtIndex:0]];
[self setCaptureVideoPreviewLayer:newCaptureVideoPreviewLayer];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[[[self captureManager] session] startRunning];
}); …Run Code Online (Sandbox Code Playgroud) 我layer通过添加以下代码行为我设置边框:
[self.avatar.layer setBorderColor:[UIColor whiteColor].CGColor];
如何更改边框上的alpha而不是avatar对象?
我们假设我有这个UIView:

有这些相对约束:
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *leftMarginConstraint;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *topMarginConstraint;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *widthConstraint;
@property (strong, nonatomic) IBOutlet NSLayoutConstraint *heightConstraint;
Run Code Online (Sandbox Code Playgroud)
好吧现在让我们假设当用户点击时UIButton按钮应该移动到视图的右下角.我们可以轻松地使用两个约束来定义按钮和底部布局指南之间的底部空间,以及从按钮和视图的右边缘定义右空间(尾随空间).
问题是UIButton已经有两个约束(左/上)和两个约束来定义它的宽度和高度,所以我们不能添加两个新约束,因为它们会与其他约束冲突.
动画场景的简单和常见情况,但它给我带来了一些问题.想法?
编辑
当用户点击时UIButton,我需要按钮:
我是否真的必须使用这个凌乱的代码?
@implementation ViewController
{
NSLayoutConstraint *_topMarginConstraint;
NSLayoutConstraint *_leftMarginConstraint;
NSLayoutConstraint *_bottomMarginConstraint;
NSLayoutConstraint *_rightMarginConstraint;
}
- (IBAction)buttonPressed:(id)sender
{
UIButton *button = sender;
// 1.
[sender setTitle:@"Second" forState:UIControlStateNormal];
// 2.
double delayInSeconds = 1.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * …Run Code Online (Sandbox Code Playgroud) 使用以下调试运行它时我的应用程序崩溃:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'NSConcreteMutableAttributedString initWithString:attributes:: nil value'
*** First throw call stack:
(
0 CoreFoundation 0x0000000102a83495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001027e299e objc_exception_throw + 43
2 CoreFoundation 0x0000000102a832ad +[NSException raise:format:] + 205
3 Foundation 0x00000001023d993e -[NSConcreteMutableAttributedString initWithString:attributes:] + 129
4 myApp 0x0000000100006da5 -[WelcomeViewController viewDidLoad] + 373
5 UIKit 0x000000010148559e -[UIViewController loadViewIfRequired] + 562
6 UIKit 0x0000000101485777 -[UIViewController view] + 29
7 UIKit 0x00000001017902e2 -[UIClientRotationContext initWithClient:toOrientation:duration:andWindow:] + 390
8 UIKit 0x00000001013cbffa -[UIWindow _setRotatableClient:toOrientation:updateStatusBar:duration:force:isRotating:] + …Run Code Online (Sandbox Code Playgroud) 因为目前这是不可能的颜色设置的SKScene对clearColor,做
-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {
self.backgroundColor = [SKColor clearColor];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
如下所示:LINK
那么如何设置背景图像SKScene呢?请尽可能具体,示例代码会很棒!
我是iOS开发的新手,我使用monotouch开发iOS应用程序,我想知道自应用程序空闲以来的时间,我得到了ObjC代码但无法将其转换为c#.这是代码:
- (void)sendEvent:(UIEvent *)event {
[super sendEvent:event];
// Only want to reset the timer on a Began touch or an Ended touch, to reduce the number of timer resets.
NSSet *allTouches = [event allTouches];
if ([allTouches count] > 0) {
// allTouches count only ever seems to be 1, so anyObject works here.
UITouchPhase phase = ((UITouch *)[allTouches anyObject]).phase;
if (phase == UITouchPhaseBegan || phase == UITouchPhaseEnded)
[self resetIdleTimer];
}
}
- (void)resetIdleTimer {
if (idleTimer) {
[idleTimer invalidate];
[idleTimer …Run Code Online (Sandbox Code Playgroud) 我有app我在使用tableView的问题是,当tableView有一个记录时,它不显示分隔线,但显示有两个记录.
tableView中的第一个单元格是textField.这是我正在使用的代码.
for (UIView *subView in cell.subviews)
{
if (subView.tag == 2 || subView.tag == 22)
{
[subView removeFromSuperview];
}
}
tableView.backgroundView=nil;
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
tableView.separatorInset = UIEdgeInsetsZero;
if(indexPath.section==0){
tagInputField =[[UITextField alloc]initWithFrame:CGRectMake(0,0,248,31)];
tagInputField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;
tagInputField.textAlignment=UITextAlignmentLeft;
tagInputField.backgroundColor=[UIColor whiteColor];
tagInputField.tag = 2;
tagInputField.delegate = self;
tagInputField.clearButtonMode = UITextFieldViewModeWhileEditing;
[tagInputField.layer setCornerRadius:5.0f];
[tagInputField.layer setMasksToBounds:YES];
tagInputField.layer.borderWidth = 0.3;
tagInputField.layer.borderColor = [UIColor darkGrayColor].CGColor;
tagInputField.font=[UIFont fontWithName:@"Myriad-Pro" size:8];
[tagInputField setText:@"Enter tag here "];
tagInputField.textColor =[UIColor grayColor];
tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
[cell addSubview:tagInputField];
return cell;
}
if(indexPath.section==1) {
UIButton *crossButton =[[UIButton …Run Code Online (Sandbox Code Playgroud) 我已尝试在我的应用.plist文件中设置以下内容:
View controller-based status bar appearance: NO
虽然这会从我的初始视图控制器中删除它,但是一旦我转到另一个视图并使用我的导航控制器返回,它就会回来,这次它不会消失.此外,我不明白为什么它会重要,但我还将模拟指标下的状态栏设置为"无",但这似乎没有帮助.我知道我将拥有导航栏,但状态栏我需要消失.

我怎么能这样做?请提供详细的答案,示例代码会很棒!
更新:这不是一个重复的解决方案,因为我尝试了所有其他解决方案,NONE似乎对我有用.最近我试过了
[[UIApplication sharedApplication]setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
Run Code Online (Sandbox Code Playgroud)
再一次,没有结果.当应用程序最初启动时,状态栏不存在,在用户访问另一个视图后,状态栏现在出现在2和其他视图中,并且不会消失.即使你回到主视图.
我有一个聊天应用程序,我的服务器在发送新消息时发送推送通知.我遇到的问题是如何让用户看到正确的视图?我channelID在推送通知中发送了一个但是如何检索它并将用户带到实际的会话中?
我正在使用此代码来检测何时单击推送通知
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
if ( application.applicationState == UIApplicationStateInactive || application.applicationState == UIApplicationStateBackground )
{
//opened from a push notification when the app was on background
}
}
Run Code Online (Sandbox Code Playgroud) 我UITableView在故事板文件中设置了几个静态单元格.
我的问题是:如何将其中一个单元格的颜色设置为透明?我已尝试使用在视图>背景下选择的单元格进入检查器并将其设置为>清除颜色,但这样做会使单元格显示"清晰"颜色,但单元格的边框仍然可见:
,
有人可以帮我实现这个没有边界的事吗?谢谢
****编辑****我已经尝试将alpha级别设置为0但这似乎没有影响.
我也试图实现以下内容,但我得到的结果与上图相同:
_topCell.backgroundColor = [UIColor clearColor];
Run Code Online (Sandbox Code Playgroud)
我也尝试过实施:
self.tableView.separatorColor = [UIColor clearColor];
Run Code Online (Sandbox Code Playgroud)
得到以下结果:

请忽略将标题与描述分开的垂直线,即UIImageView带有垂直线图像的垂直线.
只是为了给你们一个想法,我这样做是因为最终我正在寻找一个清晰/干净的单元格来添加一些圆形的矩形按钮,例如"文本消息","共享联系人"和"添加到收藏夹"按钮显示下面:

在我目前的应用程序中,我有一个通常可以解决相当长的十进制数的等式,即:0.12345或.123.但是我需要这个工作的方式是只显示1或2个十进制数,所以根据我提到的值,它基本上会产生0.12或0.1.
为了做到这一点,我做了以下几点:把我的CGFloat带到一个NSString:
CGFloat eX1 = 0.12345
NSLog(@" eX1 = %f", eX1); //This of course , prints out 0.12345
NSNumberFormatter *XFormatter = [[NSNumberFormatter alloc] init];
Xformatter.numberStyle=NSNumberFormatterDecimalStyle;
Xformatter.maximumFractionDigits=1;
NSString *eX1F = [formatter stringFromNumber:@(eX1)];
NSLog (@"eX1F = %@",eX1F); //This prints out 0.1
Run Code Online (Sandbox Code Playgroud)
但我的问题是,我需要继续使用它作为CGFloat格式后,我已经尝试通过执行将字符串带回一个数字:numberFromString但问题是只适用于NSNumber.
我可以做些什么来格式化我CGFloat并继续使用它作为一个CGFloat而不是一个NSString或NSNumber?
更新我试过:
float backToFloat = [myNumber floatValue];
Run Code Online (Sandbox Code Playgroud)
但结果是数字未格式化:0.10000我需要额外的0
ios ×11
objective-c ×8
ios7 ×3
uitableview ×2
autolayout ×1
math ×1
sprite ×1
sprite-kit ×1
statusbar ×1
uiview ×1
xamarin.ios ×1